假设我有以下 TestNG 测试类:
public class OwnTestLauncher {
@Test(dataProvider = "valid-provider")
public void validSintax(Collection<File> files) throws PlooException {
runFilesThroughCompiler(files);
}
@Test(dataProvider = "invalid-provider")
public void invalidSintax(Collection<File> files) throws PlooException {
runFilesThroughCompiler(files);
}
protected String someAlgoritmUsedByRunFilesThroughCompiler(...) { ... }
...
}
然后我想创建一些略有不同的套装,这样我就可以在不同的场合运行它们中的每一个:
public class SomeOtherFlavour extends OwnTestLauncher {
@Override
protected String someAlgoritmUsedByRunFilesThroughCompiler(files) { ... }
}
我试过运行上面显示的代码,但没有成功。我也尝试用 @Test
注释 SomeOtherFlavour
但这似乎没有帮助。有没有可能做我想做的事?
最佳答案
恐怕你必须将 someAlgoritmUsedByRunFilesThroughCompiler
提取到一个单独的接口(interface)(或抽象类)中,并编写它的不同实现类。
public interface MyAlgorithm {
String someAlgoritmUsedByRunFilesThroughCompiler(...);
}
然后,OwnTestLauncher
中的测试方法期望将此接口(interface)的实现作为附加参数,您仍然可以通过调整它们来使用您的数据提供程序。
关于java - 可以在 TestNG 测试服中使用继承吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5618299/