Ego*_*gen 53 java junit unit-testing
我们的工具包有超过15000个JUnit测试,如果其他测试失败,许多测试都会失败.例如,如果方法X.foo()使用Y.bar()和YTest.testBar()失败的功能,那么XTest.testFoo()也将失败.显然,由于X.foo()特有的问题,XTest.testFoo()也会失败.
虽然这很好但我仍然希望运行两个测试,如果可以使用指向YTest.testBar()的XTest.testFoo()来注释测试依赖项,那将是很好的.这样,人们可以立即看到X.foo()使用的功能也失败了,什么不能.
JUnit或其他地方是否有这样的注释?就像是:
public XTest {
@Test
@DependsOn(method=org.example.tests.YTest#testBar)
public void testFoo() {
// Assert.something();
}
}
Run Code Online (Sandbox Code Playgroud)
Esk*_*ola 24
我不知道它有多有用,但是如果你尝试一下,请回来告诉我们它是否有用.
Jos*_*nis 17
JUnit对此有所贡献:https://github.com/junit-team/junit.contrib/tree/master/assumes
小智 5
org.junit.FixMethodOrder
@FixMethodOrder(MethodSorters.NAME_ASCENDING)这是你的单元测试类的顶部.
您可以将方法命名为public void step1_methodName等