以前,我使用 Suite.class 指定要为具有以下结构方案的特定套件运行的测试: 套件
@RunWith(Suite.class)
@SuiteClasses({TC0.class, TC1.class...})
public class mainTester {
@BeforeClass
public static void setUp() {//create xml report - create file, start xml structure}
@AfterClass
public static void tearDown(){//close xml report - close xml structure, close writer
}
测试
@RunWith(Parameterized.class)
public class TC0 extends testXMLReporter{
//Tests with params
}
最后testXMLReporter持有规则
@Rule
public TestRule watchman = new TestWatcher(){
//@Override apply, succeeded, failed to write custom xml structure for xml report
}
但是现在我需要创建套件来动态读取文件中的数据,我从 Suite.class 切换到AllTests.class. 使其工作的唯一方法是更改我的套件 - 删除@SuiteClasses - 将@RunWith值更改为AllTests.class - 并添加suite()方法
public static TestSuite suite() {
TestSuite suite = new TestSuite();
for(Class<?> klass : CsvParser.readCSV()) {
suite.addTest(new junit.framework.JUnit4TestAdapter(klass));
}
return suite;
}
在读取文件和运行测试方面运行良好,但现在突然间我的@Before/AfterClass 注释以及@Rule没有运行(我的报告不再创建)。这是什么原因,我该如何解决?
慕妹3146593
相关分类