[英]Spring Boot junit5 tests working locally (Windows) but not in Jenkins (Linux)
我將在這里回答我自己的問題,以防它對其他人有用......
在更新到 Spring Boot 2.4.0(從 2.3.4)和 JUnit5(從 JUnit4)后,我的單元測試在 Jenkins 上開始失敗。 奇怪的是他們在當地工作。
這是在 Jenkins 的錯誤日志中:
Neither @ContextConfiguration nor @ContextHierarchy found for test class [my.PackageName.controller.ControllerTest], using SpringBootContextLoader
為什么測試在 Jenkins 上停止工作,但在本地很好?
我在 SO 上找到了類似的問題/答案,但不是我的具體問題......(如果答案已經存在,請道歉)
我花了很長時間才發現它,但關鍵是:
Neither @ContextConfiguration nor @ContextHierarchy found for test class [my.**PackageName**.controller.ControllerTest], using SpringBootContextLoader
PackageName
為駝峰式。 出於某種原因,很久以前,當我創建測試類時,我將它們放在 package 中:
package my.PackageName.controller;
解決方法是將其更改為:
package my.packagename.controller;
因為 Linux 文件系統區分大小寫,而 Windows 不區分大小寫。 對依賴項的更新似乎改變了包在某處解析的方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.