Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit test inheritance doesn't work

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> { ... }

No tests are executed at all, both concrete classes are ignored. How do I make it work? (I expect test1() to be executed for both Integer and Double).

I use JUnit 4.8.1.

Update: it appeared that problem is related with maven-surefire-plugin and not JUnit itself. See my answer below.

like image 996
Andrey Agibalov Avatar asked Jan 10 '12 19:01

Andrey Agibalov


1 Answers

Renamed all my classes to have suffix "Test" and now it works (Concrete1Test, Concrete2Test).

Update:

That's related with default settings of 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".

like image 68
Andrey Agibalov Avatar answered Sep 20 '22 04:09

Andrey Agibalov