【发布时间】:2017-05-07 03:58:45
【问题描述】:
我有大约 8 个end-to-end-test 类扩展 我的 abstract SpringContextLoadingTest 类,如下所示:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public abstract class SpringContextLoadingTest extends AbstractTestNGSpringContextTests {
}
我有带有 @SpringBootApplication 注释的主应用程序类。
当我使用 TestNG 时,我在一个组中有一些类(“通道 A”),而在另一个组中有一些类(“通道 B”)。
我为运行不同的组制作了 gradle 任务:
task runChannelA(type: Test) {
forkEvery = 1
useTestNG() {
includeGroups "channel A"
}
}
如果没有“forEvery = 1”,当运行超过 1 个测试时,端口繁忙会出现问题。
感谢下面这个简单的配置,我从 gradle 任务执行中收到了更详细的输出:
tasks.withType(Test) {
testLogging.showStandardStreams = true
}
没有它,在执行测试后,应用程序会在关闭 EntityManagerFactory 时挂起 2 分钟,但这个标志表明 gradle 拾取了它没有被要求的测试。对于每个测试,无论它在哪个组中,gradle 都会记录:
Gradle Test Executor 22 STANDARD_OUT
2016-12-21 17:10:00.115 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Neither @ContextConfiguration nor @ContextHierarchy found for test class [mypackage.OtherTest], using SpringBootContextLoader
2016-12-21 17:10:00.141 INFO --- [ Test worker] o.s.t.c.support.AbstractContextLoader : Could not detect default resource locations for test class [mypackage.OtherTest]: no resource found for suffixes {-context.xml, Context.groovy}.
2016-12-21 17:10:00.143 INFO --- [ Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [mypackage.OtherTest]: DbCongestionExploratoryTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2016-12-21 17:10:00.455 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration mypackage.Application for test class mypackage.OtherTest
2016-12-21 17:10:00.466 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@9404cc4, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@46876feb, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@dd46df5, org.springframework.test.context.support.DirtiesContextTestExecutionListener@49e2c374]
这需要很多时间,因为我还有很多其他测试。这发生在我在 IntelliJ 中看到我想要执行的测试已经通过之后。例如,我在 25 秒后看到测试已通过,但因为它正在执行与我的项目中以这种方式设置的所有其他测试一样的地狱,runChannelA 需要 3 分钟以上。有趣的是,我可以在这种奇怪的行为中停止该过程,而 IntelliJ 中的进度条会填满到最后,就像什么都没发生一样,一切都是绿色和美好的。
有人可以帮我解决这个问题吗?
【问题讨论】:
标签: java intellij-idea gradle spring-boot testng