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

huangapple go评论86阅读模式
英文:

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

问题

在我的Java代码中,我有以下3个方法。当我运行pom.xml作为Maven Install时,只有@Test方法被选择。

@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);
}

在使用maven-surefire-plugin运行时,是否有一种方式可以包含除@Test之外的注解?

我希望包括@AfterSuite和@BeforeClass。

这是我的maven-surefire-plugin配置。

<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>
英文:

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(&quot;year&quot;)
@Test (groups = {&quot;smoke&quot;})
public void newUserAuthenticationTest(String year){
    System.out.println(&quot;Sniff-&quot;+year);
}
@Parameters(&quot;year&quot;)
@BeforeClass (groups = {&quot;smoke&quot;})
public void beforeMe(String year){
    System.out.println(&quot;Before -&quot;+year);
}
@Parameters(&quot;year&quot;)
@AfterSuite (groups = {&quot;smoke&quot;})
public void afterMe(String year){
    System.out.println(&quot;After -&quot;+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 .

&lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
        &lt;version&gt;3.0.0-M5&lt;/version&gt;
        &lt;configuration&gt;
        &lt;systemPropertyVariables&gt;
            &lt;year&gt;2020&lt;/year&gt;
          &lt;/systemPropertyVariables&gt;
         &lt;suiteXmlFiles&gt;
            &lt;suiteXmlFile&gt;TestPlanLoc/FirstTestPlan.xml&lt;/suiteXmlFile&gt;
          &lt;/suiteXmlFiles&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
&lt;/plugins&gt;

答案1

得分: 0

已解决:将执行环境更改为JDK,之前是JRE。

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

英文:

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

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

huangapple
  • 本文由 发表于 2020年7月24日 19:34:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63072738.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定