我有一些继承的 TestNG 代码,使用 @Factory 创建测试用例。一切正常。然而,即使测试用例在从 @Factory 方法返回时肯定是按顺序排列的,它们也不会按该顺序执行。我想执行它们以便于调试(如果将测试放在一起比一些随机顺序对开发人员来说更容易)。
是否有捷径可寻?
我正在使用 TestNG 5.9,但如果需要可以升级。
谢谢。
我目前正在尝试做同样的事情。我发现以下内容可能对您有所帮助:
http://beust.com/weblog2/archives/000479.html
http://testng.org/doc/documentation-main.html#methodinterceptors
如果我为我的问题找到某种解决方案,如果你愿意,我可以在这里添加一些代码。
编辑
我正在检查 2 种 TestClasses 应该按照 TestNG 执行的顺序 1 2 1 2 1 2 而不是 1 1 1 2 2 2
public class ExampleInterceptor implements IMethodInterceptor {
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> paramList, ITestContext paramITestContext) {
//You have to watch out to get the right test if you have other tests in oyur suite
if (!paramITestContext.getName().equals("UnwantedTest")) {
for (IMethodInstance iMethodInstance : paramList) {
Object[] obj = iMethodInstance.getInstances();
if (obj[0] instanceof Class1) {
//DO your stuff like putting it in a list/array
} else {
//DO your stuff like putting it in a list/array with the other Testclasses
}
}
}
List<IMethodInstance> result = new ArrayList<IMethodInstance>();
//Put the results in the results
}
return result;
}
}
希望有帮助。如果你有问题问。