public abstract class GenericTests<T extends Number> {
protected abstract T getT();
@Test public void test1() {
getT();
}
}
public class ConcreteTests1 extends GenericTests<Integer> { ... }
public class ConcreteTests2 extends GenericTests<Double> { ... }
根本没有执行任何测试,两个具体类都被忽略了。我如何让它发挥作用? (我希望 test1()
对 Integer
和 Double
都执行)。
我使用 JUnit 4.8.1。
更新:问题似乎与 maven-surefire-plugin 有关,而不是 JUnit 本身。请参阅下面我的回答。
最佳答案
将我所有的类重命名为具有后缀“Test”,现在可以使用了(Concrete1Test
、Concrete2Test
)。
更新:
这与maven-surefire-plugin的默认设置有关。
http://maven.apache.org/plugins/maven-surefire-plugin/examples/inclusion-exclusion.html
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
**/Test*.java
- includes all of its subdirectories and all java filenames that start with "Test".**/*Test.java
- includes all of its subdirectories and all java filenames that end with "Test".**/*TestCase.java
- includes all of its subdirectories and all java filenames that end with "TestCase".
关于java - JUnit 测试继承不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8809175/