我的testng.xml想,如何忽略/跳过完结TestNG的类包含一些测试方法及BeforeClass及课余方法
<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>
这可能包含接近10-15多类,这是我的通用TestNG的.xml,来自不同的testdata集,我想要的是跳过com.testClass1类,特殊情况下,其余测试应该执行。
我尝试着使用我的类,IAnnotationTransformer侦听器的testng。
的代码段,
public class SkipTestClass implements IAnnotationTransformer{
private SessionProfile profile=null;
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
if (testMethod != null) {
Test test = testMethod.getDeclaringClass().getAnnotation(Test.class);
if (test != null && !test.enabled() && testMethod.getDeclaringClass().getClass().getName().equalsIgnoreCase("com.testClass1")) {
annotation.setEnabled(false);
}
}
}
}
,并调用这个监听器在测试类水平,
@Listeners(com.SkipTestClass.class),
预期结果:我假设,只有这个类com.testClass1 &它的测试方法& beforeclass & afterclass方法应该跳过,套件的其余部分应该执行。
实际结果:整个套件正在跳过。
请帮忙吗?
嗨朱利安,但如何跳过级,因为在使用您的实现,我看不出法如的setEnabled(假);如果您可以提供确切的实施,那将是有帮助的 – PrateekSethi
它们不会被跳过,因为它们根本没有运行。但为什么你想看到他们跳过(又名“我们无法运行它们,因为之前有什么不对劲”)? – juherr
这可能是因为beforeclass&afterclass也被设置为alwaysrun = true。是否有任何方法可以跳过它们 – PrateekSethi