如何测试Maven原型生成的项目

时间:2017-05-14 18:58:45

标签: java maven-archetype

我使用Maven创建了一个创建项目的原型。 为了测试项目,我通常必须生成项目并运行mvn clean install以确保它成功构建。

我一直在寻找一种方法来测试将从原型生成的项目成功构建而无需手动创建它。

我已经考虑过的选项是我可以编写一个shell脚本,它可以生成项目并测试它是否正常工作。因此,用户只需运行脚本即可确保原型项目不会失败。

有没有更好的方法可以建议任何人?

1 个答案:

答案 0 :(得分:0)

您可以为src / test / resources / projects下的每个文件夹生成一个测试项目。

每个文件夹必须包含:

  • archetype.properties文件
  • goal.txt文件

示例:

  • src / test / resources / projects /
    • test1
      • goal.txt
      • archetype.properties

原型文件包含生成项目所需的所有属性(“名称=值”语法)。 目标文件包含您要执行的mvn目标(例如:验证)

然后将以下插件添加到原型的pom.xml中:

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-archetype-plugin</artifactId>
            <version>3.0.1 </version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

您可以使用:mvn archetype:integration-test

进行集成测试

参考:https://maven.apache.org/archetype/maven-archetype-plugin/integration-test-mojo.html

相关问题