测试在 intelliJ 中运行良好,但因 gradle 而失败

Test runs fine in intelliJ and fails with gradle

从 IntelliJ 开始测试工作正常。 gradle returns:

中的相同测试
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.gradle.kts 中的这一行搞砸了。

logManager = "org.apache.logging.log4j.jul.LogManager"

根据堆栈跟踪(参见 build/test-reports),这是由于类路径上的日志记录框架不同所致。

一个快速修复方法是删除以下两个依赖项以及 JUnitPlatformExtensionlogManager 配置:

// 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