I just realized (when porting legacy code from JUnit 4 to JUnit 5) that some of our test methods fail because they donβt have @Test annotation. They do not have this because they redefine methods from an abstract superclass (where the annotation is present).
I can easily fix this by adding @Test to each method. But I was wondering if this is intentional behavior. It has changed from JUnit 4 to 5, but I cannot find anything in the official JUnit5 user guide or anywhere else.
In accordance with this question, annotations are usually not inherited. But it looks like this was intentionally changed in the new version of JUnit. (Or am I missing something?)
Abstract test class
import org.junit.jupiter.api.Test; abstract class AbstractJUnit5Test { @Test void generalTest() { System.out.println("This is a test in the abstract class"); } @Test abstract void concreteTest(); }
Specific test class
import org.junit.jupiter.api.Test; class ConcreteJUnt5Test extends AbstractJUnit5Test {
source share