问题:如何在testng xml 中设置方法优先级,而不是在class.method级别上添加具有优先级标签的方法?
我尝试为此找到答案,但我无法在任何地方找到这个特定的观点。
用例:我可以通过程序上生成testng XML并调用测试 基于在外部文件中写入的给定方法名称作为数据源的方法。
我认为有多种方法可以做到这一点。使用实现注释变压器的侦听器就是其中之一。您可以做这样的事情:
public class SetPriorityListener implements IAnnotationTransformer {
@Override
public void transform(final ITestAnnotation annotation, final Class testClass,
final Constructor constructor, final Method method) {
if ("myTestName".equals(method.getName())) {
annotation.setPriority(getTestPriority());
}
}
private int getTestPriority() {
//logic to get priority for this test
return 0;
}
}
您可以在官方文档中阅读有关AnnotationTransFormer的更多信息:http://testng.org/doc/documentation-main.html#annotationtrantationtransformers