我有假的testng.xml,
<% @merchant_working_hours.each do |key,value| %>
<%= key: value%>
<% end %>
这可能包含更多接近10-15的类,这是我的通用testng.xml,来自不同的testdata集合,我想要的是跳过com.testClass1类,对于特定情况,其余的测试应该执行。
我尝试使用testng的IAnnotationTransformer监听器来实现我的类。
代码段是,
<suite name="TestSuite" parallel="false">
<test name="smoke" preserve-order="true" verbose="2">
<groups>
<run>
<include name="smoke"/>
</run>
</groups>
<classes>
<class name="com.testClass1"/>
<class name="com.testClass2"/>
</classes>
</test>
</suite>
并在Test Class级别调用此侦听器,如
@Listeners(com.SkipTestClass.class),
预期结果:我假设,只有这个类com.testClass1&amp;它的测试方法&amp;前课程&amp;应该跳过afterclass方法,并且应该执行套件的其余部分。
实际结果:整个套件被跳过。
请帮忙吗?
答案 0 :(得分:1)
整个套件都被跳过了。
我想是因为你的听众看起来不错,因为跑步失败了。您可以设置更高的详细级别来检查发生的情况。
BTW,IMethodInterceptor是一个更好的倾听者选择,因为它不依赖于在课堂和/或测试中可能存在或不存在的注释。
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
List<IMethodInstance> result = new ArrayList<IMethodInstance>();
for (IMethodInstance m : methods) {
if (m.getDeclaringClass() != testClass1.class) {
result.add(m);
}
}
return result;
}
并且更喜欢在套件描述中添加此侦听器:
<suite name="TestSuite" parallel="false">
<listeners>
<listener class-name="...MyListener"/>
</listeners>
<test name="smoke" preserve-order="true" verbose="2">
<groups>
<run>
<include name="smoke"/>
</run>
</groups>
<classes>
<class name="com.testClass1"/>
<class name="com.testClass2"/>
</classes>
</test>
</suite>
答案 1 :(得分:-1)
您可以使用套件排除/包含测试用例。
@RunWith(Suite.class)
@Suite.SuiteClasses({
AuthenticationTest.class
/* USERRestServiceTest.class*/
})
public class JunitTestSuite
{
}
然后使用跑步者
@Category(IntegrationTest.class)
public class TestRunner {
@Test
public void testAll() {
Result result = JUnitCore.runClasses(JunitTestSuite.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
if (result.wasSuccessful()) {
System.out.println("All tests finished successfully...");
}
}
}
更多详情 - TestRunner Documentation