在运行时将测试类添加到TestNG套件中

时间:2018-06-28 11:08:55

标签: java testng

我想通过以下方式在运行时更改测试范围:

import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.xml.XmlClass;


public abstract class ATest {

    @BeforeClass
    public void checkAndInit(ITestContext context) {
        if (TestUtils.isMonday()) {
            context.getCurrentXmlTest().getXmlClasses().add(new XmlClass(MondayTest.class.getName()));
            throw new SkipException("Not a good day for test");
        }

    }
}

已跳过子级测试类(BTest扩展了ATest),但看起来测试范围未更改。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Z" configfailurepolicy="continue">
    <test name="A">
      <classes>
        <class name="com.BTest" />
      </classes>
    </test>
</suite>

0 个答案:

没有答案