我应该在哪里放置集成测试助手/工具?

时间:2019-01-29 00:37:29

标签: java maven automated-tests

我正在向Maven项目添加集成测试。我的文件夹结构如下所示:

  • src / main / java

  • src / test / java

  • src / integrationtest / java

要运行集成测试,我将必须编写一些代码以集成到API和Azure Keyvault。

1)我想保留Maven约定,并尝试使所有内容尽可能地井井有条。所有这些代码都应该放在哪里?所有集成测试都将引用它。

  • src / keyvaultapi / java吗?

  • src / integrationtest / keyvaultapi吗?

2)如何从集成测试中访问此代码?

现在,我已将以下内容添加到我的pom.xml中:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.10</version>
            <executions>
                <execution>
                    <id>add-test-source</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/integrationtest/java</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

1 个答案:

答案 0 :(得分:0)

“默认情况下” integration-tests文件夹为/ src / it,但我也不喜欢它。太短。 :)

为集成测试类添加一些前缀或后缀(例如“ IT”)会有所帮助: MySuperApiIT.java

您的build-helper-maven-plugin部分错误且不完整,应该是这样的:

<execution>
    <id>add-integration-test-sources</id>
    <phase>generate-test-sources</phase>
    <goals>
        <goal>add-test-source</goal>
    </goals>
    <configuration>
        <sources>
            <source>src/integrationtest/java</source>
        </sources>
    </configuration>
</execution>
<execution>
    <id>add-integration-test-resources</id>
    <phase>generate-test-resources</phase>
    <goals>
        <goal>add-test-resource</goal>
    </goals>
    <configuration>
        <resources>
            <resource>
                <directory>src/integrationtest/resources</directory>
            </resource>
        </resources>
    </configuration>
</execution>

此外,最好不要“默认”运行集成测试,而是将它们链接到某些配置文件。

非常好的HOWTO:https://www.petrikainulainen.net/programming/maven/integration-testing-with-maven/

另一个示例:https://github.com/Gmugra/net.cactusthorn.maven