从 IntelliJ 开始测试工作正常。
gradle 中的相同测试返回:
13:15:20.148 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding PropertySource 'Inlined Test Properties' with highest search precedence
╷
└─ JUnit Jupiter ✔
├─ HelloIntegrationTest ✔
│ └─ testHello() ✘ Failed to load ApplicationContext
最后一个调试日志行在 IntelliJ 中是相同的。不同之处在于,在 IntelliJ 中测试开始并成功,但在 gradle 中它停止了。
在 IntelliJ 中,如果我故意让它失败,测试就会失败。所以我确信它会一直运行到最后。
--debug --info --stacktrace 没有帮助,因为日志在测试前停止。
我是 Gradle 的初学者。欢迎任何线索如何调试它......
使用 Gradle 4.6、spring boot 2 版本、JUnit 5.0.1。
整个类(class)和要复制的 repo 都在那里:
https://github.com/ununhexium/springdwarf/blob/4480792f9d257dfc726fcf956ca5e452675b18e9/src/test/java/net/lab0/shell/HelloIntegrationTest.java
最佳答案
根据堆栈跟踪(见 build/test-reports
),这是由于类路径上有不同的日志框架造成的。
一个快速的解决方法是删除以下两个依赖项以及 logManager
JUnitPlatformExtension
的配置:
// To use Log4J's LogManager
testRuntimeOnly("org.apache.logging.log4j:log4j-core:$log4jVersion")
testRuntimeOnly("org.apache.logging.log4j:log4j-jul:$log4jVersion")
切换到 Gradle 对在 JUnit 平台上运行测试的原生支持也解决了这个问题:
https://github.com/ununhexium/springdwarf/pull/1
关于spring-boot - 测试在 IntelliJ 中运行良好,但 gradle 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49221176/