默认情况下,不要在Maven和每个IDE(Eclipse,IntelliJ,...)中运行一个缓慢的JUnit测试类,而不需要显式的TestSuite [英] Do not run a category of slow JUnit tests by default in Maven and every IDE (Eclipse, IntelliJ, ...) without an explicit TestSuite
问题描述
自然,没有开发人员(甚至是默认构建作业)想要运行这些测试。只有一个特定的单独的构建作业才有时间运行它们。所以这些测试需要默认禁用。
JUnit的类别似乎是完美的:我用 @Category(SlowTests.class)
注释那些慢速测试。问题是它们仍然运行,因为:
- 我不想维护TestSuite类,因为我们每天添加测试。我有0个TestSuite类:Maven,IntelliJ和Eclipse只是从我的模块运行所有的Test类。包括所有这些缓慢的测试。
- 即使我们有TestSuite类,大多数开源贡献者仍然会尝试从IntelliJ或Eclipse运行所有测试类,认为它挂起并放弃运行试验。默认情况下,这些缓慢测试需要排除。最好在IntelliJ或Eclipse中没有任何额外的配置。
如何在默认情况下排除一个类型的慢JUnit测试,而不使用一个显式的TestSuite?
这个在默认情况下工作,在Maven,IntelliJ和Eclipse :
import static org.junit.Assume.assumeTrue;
@Test
public void mySlowTest(){
putsTrue(true.equals(System.getProperty(runSlowTests)));
...
}
要运行它们,只需添加VM参数 -DrunSlowTests = true
。
语义上,这是完全错误的。但它有效:)
I have a set of really slow tests, which take a week to run. (They literally run some code non-stop for about a week).
Naturally, no developer (or even the default build job) wants to run these tests. Only a specific, separate build job has the time to run them. So these tests needs to be disabled by default.
JUnit's categories seemed perfect for this: I annotated those slow tests with @Category(SlowTests.class)
. Problem is that they are still run because:
- I don't want to maintain TestSuite classes because we add Tests on a daily basis. I have 0 TestSuite classes: Maven, IntelliJ and Eclipse just run all the Test classes from my module. Including all those slow tests.
- Even if we had TestSuite classes, most of the open source contributors would still try to run all Test classes from IntelliJ or Eclipse, think it hangs and give up running tests. Those slow tests needs to be excluded by default. Preferably without any extra configuration in IntelliJ or Eclipse.
How do I exclude a category of slow JUnit tests by default without using an explicit TestSuite?
This works by default, in Maven, IntelliJ and Eclipse:
import static org.junit.Assume.assumeTrue;
@Test
public void mySlowTest() {
assumeTrue("true".equals(System.getProperty("runSlowTests")));
...
}
To run them anyway, simply add VM argument -DrunSlowTests=true
.
Semantically speaking, it's totally wrong. But it works :)
这篇关于默认情况下,不要在Maven和每个IDE(Eclipse,IntelliJ,...)中运行一个缓慢的JUnit测试类,而不需要显式的TestSuite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!