我目前使用IAnnotationTransformer排除其中的名称中包含特定字符串的XML中列出的所有测试,例如:如何获取testMethod调用的所有方法? (Java中,TestNG的,IAnnotationTransformer)
@Override
@SuppressWarnings("rawtypes")
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
if(testMethod.getName().contains("StringGoesHere")){
annotation.setEnabled(false);
}
这工作得很好,但是由于我的测试的命名约定以及我需要排除的大量测试,理想的解决方案是找到一种排除测试的方法,如果它调用特定的方法。比如,我要排除的呼吁方法.clickUserSettings()如下所示的所有测试:
@Test
public void editUserDetailsOnStackOverflow() {
final StackOverflow so = stackOverflow.loginAsMe()
.clickUserSettings()
.changeUserEmail()
.clickSave()
.assertChangeSuccessful();
}
有谁知道我如何能够实现这一目标?我觉得我已经探索过所有其他途径(类,包,testMethods,groups,xml等),并且必须以这种方式完成这个任务,原因是我目前有40,000个测试(其中15,000个可能会被排除在外由测试仪设置的browserMode变量)这是一般的想法,我希望能实现:
@Override
@SuppressWarnings("rawtypes")
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
if(testMethod.getAllCalledMethods.contains(".clickUserSettings()")){
annotation.setEnabled(false);
}
如果可以做到这一点,将解决我的问题,
干杯
为什么群体不适合用途? –
嗯 - 没有什么开箱就会给你。考虑编写一个外部脚本作为预测试或beforesuite运行 - 生成这些方法的列表 - 您可以在注释转换器中禁用这些方法。一些方法:http://stackoverflow.com/questions/930289/how-can-i-find-all-the-methods-that-call-a-given-method-in-java。你可以在文件中做一个grep或者在一个包含测试的快速循环中考虑一些解决方案 –