简体   繁体   English

Spring 引导 junit5 测试在本地 (Windows) 工作,但在 Jenkins (Linux) 中不工作

[英]Spring Boot junit5 tests working locally (Windows) but not in Jenkins (Linux)

I'm going to answer my own question here in case it is useful for anyone else...我将在这里回答我自己的问题,以防它对其他人有用......

After updating to Spring Boot 2.4.0 (from 2.3.4), and to JUnit5 (from JUnit4), my unit tests started failing on Jenkins.在更新到 Spring Boot 2.4.0(从 2.3.4)和 JUnit5(从 JUnit4)后,我的单元测试在 Jenkins 上开始失败。 The strange thing was that they were working locally.奇怪的是他们在当地工作。

This was in the error log on Jenkins:这是在 Jenkins 的错误日志中:

Neither @ContextConfiguration nor @ContextHierarchy found for test class [my.PackageName.controller.ControllerTest], using SpringBootContextLoader

Why have the tests stopped working on Jenkins but are fine locally?为什么测试在 Jenkins 上停止工作,但在本地很好?

I found similar questions / answers on SO, but not my specific issue... (apologies if the answer is already out there)我在 SO 上找到了类似的问题/答案,但不是我的具体问题......(如果答案已经存在,请道歉)

It took me too long to spot it, but the key is:我花了很长时间才发现它,但关键是:

Neither @ContextConfiguration nor @ContextHierarchy found for test class [my.**PackageName**.controller.ControllerTest], using SpringBootContextLoader

PackageName is in camel case. PackageName为驼峰式。 For some reason, a long time ago, when I created my test classes I put them in the package:出于某种原因,很久以前,当我创建测试类时,我将它们放在 package 中:

package my.PackageName.controller;

And the fix is to change this to:解决方法是将其更改为:

package my.packagename.controller;

Because the Linux file system is case sensitive, and Windows is not.因为 Linux 文件系统区分大小写,而 Windows 不区分大小写。 And the updates to the dependencies seems to have changed the way packages are resolved somewhere.对依赖项的更新似乎改变了包在某处解析的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM