Apart from the renaming of your classes as something like Scen1Test.java and Scen2Test.java as suggested by @viniciusartur, which shall help Maven to recognize the test classes to execute them using surefire-plugin.
Another point to note here is that the reason due to which the @Before
, @BeforeClass
, @After
etc are not executed independently without a @Test
method is that only
The Test annotation tells JUnit that the public void method to which
it is attached can be run as a test case. To run the method, JUnit
first constructs a fresh instance of the class then invokes the
annotated method.
From the documentation of @Before in JUnit
Annotating a public void method with @Before causes that method to be
run before the Test method. The @Before methods of superclasses will
be run before those of the current class.
So inferring as this, while annotations are processed, if there is no @Test annotation present in the class under /src/test/java
(relative to the question based on maven), no further annotations are meaningful to be processed.
Just to note, if you extend this class with another SubClassTest.java consisting of a @Test method
, all these methods would be executed then. Since they are processed based on what(@Test
) to act on to.