我正在以编程方式运行测试用例,例如,
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng=new TestNG();
testng.setTestClasses(new Class[] { UserGroupTest.class });
testng.addListener(tla);
testng.run();
我在 UserGroupTest.class
中保留了 8 个测试用例
是否可以通过 testCase 添加测试用例而不是添加整个类文件?因为我想在条件基础上运行测试用例。怎么做达?
最佳答案
如果您只想运行这些类中的某些方法,您有几个选择:
- 将这些方法放在一个组中并调用 testng.setGroups(..)。
创建一个模拟以下 XML 的 testng.xml(内存中可能是最简单的,因为您使用的是 API):
<classes> <class name="test.methods.SampleMethod1"> <methods> <include name="shouldRun1" /> <include name="shouldRun2" />
关于java - 添加测试用例的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5460395/