Search code examples
javatestngmaven-surefire-plugin

How to allow other than @Test annotation to be executed via maven-surefire-plugin. I want @BeforeClass and @AfterSuite to be picked


In my Java code , I have below 3 methods .When I ran the pom.xml Run as Maven Install , only the @Test method get picked .

    @Parameters("year")
@Test (groups = {"smoke"})
public void newUserAuthenticationTest(String year){
    System.out.println("Sniff-"+year);
}
@Parameters("year")
@BeforeClass (groups = {"smoke"})
public void beforeMe(String year){
    System.out.println("Before -"+year);
}
@Parameters("year")
@AfterSuite (groups = {"smoke"})
public void afterMe(String year){
    System.out.println("After -"+year);
}

Is there a way to include annotations other than @Test when running via maven-surefire-plugin?

I wish to have @AfterSuite ,@BeforeClass

Here is my maven-surefire-plugin configuration .

<plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
        <systemPropertyVariables>
            <year>2020</year>
          </systemPropertyVariables>
         <suiteXmlFiles>
            <suiteXmlFile>TestPlanLoc/FirstTestPlan.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
</plugins>

Solution

  • It solved when changing the Execution environment to JDK , previously it was JRE.

    enter image description here