Java 可以在TestNG测试套件中使用继承吗?
假设我有以下TestNG测试类:Java 可以在TestNG测试套件中使用继承吗?,java,unit-testing,testing,testng,Java,Unit Testing,Testing,Testng,假设我有以下TestNG测试类: public class OwnTestLauncher { @Test(dataProvider = "valid-provider") public void validSintax(Collection<File> files) throws PlooException { runFilesThroughCompiler(files); } @Test(dataProvider = "inva
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(...) { ... }
...
}
我试过运行上面显示的代码,但没有成功。我也试着用
@Test
注释someotherflavor
,但这似乎没有帮助。有可能完成我想做的吗?恐怕您必须通过编译器将SomeAlgorithmusedByRunflesthrCompiler
提取到一个单独的接口(或抽象类)中,并编写它的不同实现类
public interface MyAlgorithm {
String someAlgoritmUsedByRunFilesThroughCompiler(...);
}
OwnTestLauncher
中的测试方法期望将此接口的实现作为一个附加参数,并且您仍然可以通过调整它们来使用数据提供程序。这肯定会起作用:如果您告诉TestNG运行其他风格,它应该会看到您的两个测试方法。你看到不同的东西了吗?更进一步:您可以在OwnTestLauncher类上放置@Test。
public interface MyAlgorithm {
String someAlgoritmUsedByRunFilesThroughCompiler(...);
}