java – JUnit测试继承不起作用

前端之家收集整理的这篇文章主要介绍了java – JUnit测试继承不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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()).

我使用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”.

原文链接:https://www.f2er.com/java/126206.html

猜你在找的Java相关文章