2014-01-23 49 views
0

如何在特定模块中使用测试运行单独的文件夹?如何运行单独的测试?

我的模块:

<modules> 
     <module>common</module> 
     <module>foo</module> 
     <module>bar</module> 
</modules> 

每个模块有一个2-3测试文件夹。我需要在模块栏中运行测试文件夹“utils”。

我做了限制为球队 “MVN测试”:

<plugins> 

    <plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
     <excludes> 
     <exclude>**/utils/**</exclude> 
     </excludes> 
    </configuration> 
    <executions> 

     <execution> 
     <id>surefire-itest</id> 
     <phase>integration-test</phase> 
     <goals> 
      <goal>test</goal> 
     </goals> 
     <configuration> 
      <excludes> 
      <exclude>none</exclude> 
      </excludes> 
      <includes> 
      <include>**/utils/**</include> 
      </includes> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

</plugins> 

MVN测试 - 运行,除 “utils的” 所有的测试。 mvn integration-test - 运行所有测试。

现在我只需要启动“utils”。我该如何解决这个问题?

回答

0

选项之一是使用various profiles通过mvn test运行不同的surefire exections(以及不同的包括和排除)。

选项二是使用failsafe pluginmvn verify。这使得仅仅运行单元测试或单元测试和集成测试变得容易;仅运行集成测试是可能的,但是很尴尬。

不要mvn integration-test使用万无一失插件。通常最好不要使用mvn integration-test。出于某些原因,请参阅introduction to the maven lifecycle

0

只是在utils的测试创建另一个并将其绑定到你想要在运行它们的阶段。

,你可以使用categories,以及如果你正在使用JUnit可能组的测试。

0

我发现了一个解决这个问题:

MVN测试 - 运行所有测试除 “utils的” MVN测试-P utilsTest - 仅运行测试 “utils的”

<profiles> 
    <profile> 
     <id>utilsTest</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <configuration> 
         <exclude>none</exclude> 
         <includes> 
          <include>**/utils/**</include> 
         </includes> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 

    <profile> 
     <id>test</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <configuration> 
         <excludes> 
          <exclude>**/utils/**</exclude> 
         </excludes> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 
相关问题