如果它们具有参数group =“ some”,并且执行了多个带有/不带有testNG.xml文件中的组定义的测试,我无法弄清楚如何从测试中跳过测试。
让我整理一下自己拥有的东西。
@Test
public void shouldBeStatusCodeEqualTo200WhenGetRequestPerformed() {
req.get().then().statusCode(200).log().ifValidationFails();
System.out.println(req.get().getBody().asString());
System.out.println("Status code is 200");
}
@Test(dataProvider = "queryParmsAccountSummaryData", dataProviderClass = AccountSummaryQueryStringsDataProvider.class, groups = "queryStringRequired")
public void shouldBeStatusCodeEqualTo200WhenGetRequestWithQueryStringParmPerformed(Map<String, String> queryStringParms) {
req.params(queryStringParms);
req.given().when().get().then().statusCode(200);
System.out.println(req.get().getBody().asString());
System.out.println("Status code is 200");
TestNG.xml
<test thread-count="5" name="GetAccountSummaryByCompany" parallel="classes">
<parameter name="accountSummaryByCompany" value="th/rfff/ee" />
<parameter name="customerCode" value="123" />
<parameter name="countryCode" value="NOS" />
<groups>
<run>
<include name="queryStringRequired" />
</run>
</groups>
<classes>
<class
name="accMgn.accountSummaryByCompany.GetAccountSummaryByCompany" />
</classes>
</test>
<test thread-count="5" name="GetLegalEntity" parallel="classes" enabled="true">
<parameter name="legalEntity" value="fe/juy/fds" />
<classes>
<class name="accMgn.legalEntity.GetLegalEntity" />
</classes>
</test>
如果我运行TestNG.xml,它将执行两个测试。即使未在TestNG.xml中定义该组。如何使其跳过?
答案 0 :(得分:0)
您可以根据需要使用IAnnotationTransformer
并覆盖transform
方法。
示例:
public class AnnotationTransformer implements IAnnotationTransformer {
@Override
public void transform (final ITestAnnotation annotation, final Class testClass, final Constructor testConstructor,
final Method testMethod) {
String [] groups = annotation.getGroups ();
for (String group : groups) {
if (group.equals ("some")) {
annotation.setEnabled (false);
break;
}
}
}
}
不要忘记在testng.xml
块的listener
文件中注册侦听器,如下所示:
<listeners>
<listener class-name="your.package.YourListenerClass" />
</listeners>