当前的实现是这样的,如果测试方法中指定的任何组与套件文件中指定的任何组匹配,则包含测试以运行。
目前没有规定将这种“任何匹配”的实现更改为“所有匹配”。但是您可以使用IMethodInterceptor
.
(此外,对于有问题的具体示例,您可以通过提及group3
作为排除组来实现预期的结果。但这在许多其他情况下不起作用)。
import java.util.Arrays;
public class MyInterceptor implements IMethodInterceptor {
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
String[] includedGroups = context.getIncludedGroups();
Arrays.sort(includedGroups);
List<IMethodInstance> newList = new ArrayList<>();
for(IMethodInstance m : methods) {
String[] groups = m.getMethod().getGroups();
Arrays.sort(groups);
// logic could be changed here if exact match is not required.
if(Arrays.equals(includedGroups, groups)) {
newList.add(m);
}
}
return newList;
}
}
然后在您的测试类之上,使用@Listeners
注释。
@Listeners(value = MyInterceptor.class)
public class MyTestClass {
}