我有几个测试,并与他们一起使用junit。在我所有的测试文件中,我都有junit @Rule语句。喜欢:
public @Rule
TestWatcher resultReportingTestWatcher = new TestWatcher(this);
我的所有测试文件中都包含此语句以及其他几个语句。代码的这种重复让我有些烦恼,因为我认为这些行可以移到单独的位置并可以从那里使用。
我不太确定是否可以做到这一点,因为我很陌生junit
。需要机智。
您可以将commonRule
放在父类中:
public class AbstractTest {
@Rule public SomeRule someRule = new SomeRule();
}
public class YourTest extends AbstractTest {
@Test public void testMethod() {
someRule.blah();
// test some things
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句