我的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