2017-10-17 188 views
0

我正在研究一个大的Maven Java项目,该项目包含TestNG自动测试套件和Cucumber套件自动测试套件。我意识到这并不理想,但不同的测试套件是由不同的子团队在项目的不同阶段编写的。展望未来,我们打算将这个项目分成更小的项目,但现在我们坚持这个组合。在pom.xml中配置两次Maven插件

surefire插件可用于从Maven运行这些测试,但插件需要针对我们的pom.xml中的每个配置不同。

对于Cucumber,我们正在与cucumber-jvm-parallel-plugin一起使用它,它是配置是这样的:

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.20.1</version> 
      <configuration> 
       <forkCount>${threads}</forkCount> 
       <reuseForks>true</reuseForks> 
       <includes> 
        <include>**/Parallel*IT.class</include> 
       </includes> 
      </configuration> 
     </plugin> 

对于我们TestNG测试,配置是这样的:

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.20.1</version> 
      <configuration> 
       <suiteXmlFiles>${file}</suiteXmlFiles> 
       <skipTests>false</skipTests> 
       <properties> 
        <property> 
         <name>suitethreadpoolsize</name> 
         <value>${threads}</value> 
        </property> 
       </properties> 
      </configuration> 
     </plugin> 

我们不Maven专家等,目前,我们只是将我们不希望用于我们正在运行的套件的插件注释掉。显然这很麻烦,也不是最好的做法,所以我非常感谢任何有关我们应该如何解决这个问题的建议。我们能否合理地在pom.xml中定义插件两次,并以某种方式传递一个标志来指示应该运行哪个版本?非常感谢您阅读我的问题。

+0

集成测试应该使用maven-failsafe-plugin ...,它具有默认的命名模式... – khmarbaise

回答

1

使用maven profiles选择适当的配置:

添加此片段:

<profiles> 
    <profile> 
     <id>Cucumber</id> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <forkCount>${threads}</forkCount> 
        <reuseForks>true</reuseForks> 
        <includes> 
         <include>**/Parallel*IT.class</include> 
        </includes> 
       </configuration> 
      </plugin> 
     </plugins> 
    </profile> 
    <profile> 
     <id>TestNG</id> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <suiteXmlFiles>${file}</suiteXmlFiles> 
        <properties> 
         <property> 
          <name>suitethreadpoolsize</name> 
          <value>${threads}</value> 
         </property> 
        </properties> 
       </configuration> 
      </plugin> 
     </plugins> 
    </profile> 
</profiles> 

和改变这种

<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.20.1</version> 
    </plugin> 
    <!-- delete on of the entries --> 
</plugins> 

你必须在命令行pecify所需的配置:

mvn test -P Cucumber 
    mvn test -P TestNG 

位还可以同时运行在一次:

mvn test -P Cucumber -P TestNG 
mvn test -P Cucumber,TestNG 
+0

你也可以为你的测试(cuke和TestNG)添加许多配置文件,例如烟雾,全部等。 – dimyo

+0

我做了以上建议的更改,现在我的测试正在按照需要工作。我非常感谢答案。谢谢。 –

1

创建每个组要运行测试下游Maven项目。更多的工作在前面,但它很快就会得到回报。

+0

是的,很好的答案 - 谢谢。这将是长期计划。在短期内,我在其他答案中实施了这些建议,并且他们的工作很棒。 –

+0

很棒,你找到了适合你的解决方案。我发现配置文件使得难以制作可重复的版本。这可能与您的相关或不相关。 –