加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – JUnit测试继承不起作用

发布时间:2020-12-14 19:28:39 所属栏目:Java 来源:网络整理
导读:public abstract class GenericTestsT extends Number { protected abstract T getT(); @Test public void test1() { getT(); }}public class ConcreteTests1 extends GenericTestsInteger { ... }public class ConcreteTests2 extends GenericTestsDouble {
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”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读