【发布时间】:2017-03-03 13:18:32
【问题描述】:
我目前正在使用 IAnnotationTransformer 排除 XML 中列出的所有测试,这些测试的名称中包含特定字符串,例如:
@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、组、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 运行的外部脚本 - 生成这些方法的列表 - 您可以在注释转换器中禁用它。一些方法:stackoverflow.com/questions/930289/…。您可以在文件中执行 grep 或快速循环包含的测试..想一些解决方案
标签: java testing junit annotations testng