JUnit参数化测试:如何仅从IntelliJ / Eclipse中运行1个特定测试? [英] JUnit parameterized tests: how do I run only 1 specific test from IntelliJ/Eclipse?
问题描述
我有一个 @参数化
junit测试,产生50个测试:
I have a @Parameterized
junit test that spawns 50 tests:
@RunWith(Parameterized.class)
public class NurseRosteringSolveAllTurtleTest ... {
@Parameterized.Parameters(name = "{index}: {0}")
public static Collection<Object[]> getSolutionFilesAsParameters() {
return ... // returns 50 Files.
}
public NurseRosteringSolveAllTurtleTest(File unsolvedDataFile) {
...
}
...
@Test
public void solveDataFile() {
...
}
}
运行需要一个小时(这是不可能缩短的时间,它们是集成测试)。测试28失败。
Running it takes an hour (and it's impossible to shorten that time, they are integration tests). Test 28 fails.
如何单独运行测试28,而不运行其他49个测试?在不更改实际代码的情况下,只需在IntelliJ(或Eclipse的)运行配置中简单地配置 -D
或类似的内容。
How do I run test 28 alone, without running the other 49 tests? Without changing the actual code, by simply configuring a -D
or something similar in IntelliJ's (or Eclipse's) run configuration.
推荐答案
Eclipse现在(从Mars M4版本开始)不仅可以从参数化测试类中运行,而且可以运行任何种类的子树。
Eclipse is now (as of the Mars M4 release) able to run not just a single test from the Parameterized test class but any kind of subtree.
这可以是:
- 单个数据集的所有方法返回通过@参数化方法
- 单个@ Test-method的所有数据集
如上所述,也可以通过将测试名称输入到启动配置中提交的方法文本中来指定测试。将有一个标记表示该方法不存在,但测试将会运行。
And as already mentioned, the test can also be specified by entering the tests name into the "method" text filed within the launch configuration. There will be a marker indicating that the method doesn't exist, but the test will run anyway.
请参阅这篇博文详情。
这篇关于JUnit参数化测试:如何仅从IntelliJ / Eclipse中运行1个特定测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!