1

我在这里阅读了有关使用 Surefire 插件进行单元测试和使用 Failsafe 插件进行集成测试的信息,但我仍然不清楚 POM 在由父模块和多个子模块组成的 Maven 项目中应该如何看待,每个子模块都有自己的 POM 文件.

问题

  • 有没有人在他们的每个模块中实现了集成测试和单元测试?
  • 如果是这样,您能否展示您的 POM,以便我提供一个良好工作配置的示例?
4

2 回答 2

2

Apache Stanbol项目使用 surefire 插件进行单元测试和集成测试。它可以成为你的一个很好的例子。

以下是链接:父模块集成测试和 Stanbol 的组件之一,它有自己的单元测试,factstore

于 2012-03-08T16:02:24.683 回答
1

请参阅我对问题的回答:如何在 Maven 2 中的两个测试套件之间切换? 我更喜欢 maven 模块 - 很容易实现,你不需要其他插件的知识。

如果你使用,你可以在你的父 pom 中定义(只有一个地方):

     <profile>
                    <id>normal</id>
                    <activation>
                            <activeByDefault>true</activeByDefault>
                    </activation>
                    <build>
                            <plugins>
                                    <plugin>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-surefire-plugin</artifactId>
                                            <configuration>
                                                    <excludedGroups>integration</excludedGroups>
                                            </configuration>
                                    </plugin>
                            </plugins>
                    </build>
            </profile>
<profile>
                    <id>integration</id>

                    <build>
                            <plugins>
                                    <plugin>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-surefire-plugin</artifactId>
                                            <configuration>
                                                    <includedGroups>integration</includedGroups>
                                            </configuration>
                                    </plugin>
                            </plugins>
                    </build>
            </profile>

通过以下方式注释所有集成测试:

@Test(groups="integration")

如果您使用junit,请参阅类别

您通过以下方式运行正常测试:mvn clean install集成测试通过mvn -Pintegration clean install

于 2012-03-08T20:28:55.707 回答