java - JUnit 测试继承不起作用

标签 java maven junit surefire

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()IntegerDouble 都执行)。

我使用 JUnit 4.8.1。

更新:问题似乎与 maven-surefire-plugin 有关,而不是 JUnit 本身。请参阅下面我的回答。

最佳答案

将我所有的类重命名为具有后缀“Test”,现在可以使用了(Concrete1TestConcrete2Test)。

更新:

这与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/

相关文章:

java - 实现一个函数来检查链表是否是回文-无递归,在堆栈上,无反向

maven - 从 Azure 管道 maven 构建的单元测试访问安全变量

java - 无法获取 'https://google.bintray.com/.../maven-metadata.xml' 。从服务器 : Forbidden 收到状态码 403

java - 使用 maven-antrun-plugin 解压文件的正则表达式定义的多个文件

java - MockMvc测试: model() and hasItem() methods are undefined

xml - 使用 JUnit 样式的 xml 输出的 Lua 自动化测试?

java - JUnit for Spring mvc 服务方法 void 返回类型

java - 我得到了 NullPointerException

java - splunk 将堆栈跟踪的每一行报告为单独的事件

java - 找到最少的列数