In Maven is it possible to keep integration tests in a separate folder from unit tests?

后端 未结 1 2067
挽巷
挽巷 2020-12-14 07:10

On the Maven and Integration Testing page it says:

The Future Rumor has it that a future version of Maven will support something like src/it/java in

相关标签:
1条回答
  • 2020-12-14 07:22

    You can put the IT'ss into different folder like this:

    .
    |-- pom.xml
    `-- src
        |-- it
        |   `-- java
        |       `-- com
        |           `-- soebes
        |               `-- maui
        |                   `-- it
        |                       `-- BitMaskIT.java
        |-- main
        |   `-- java
        |       `-- com
        |           `-- soebes
        |               `-- maui
        |                   `-- it
        |                       `-- BitMask.java
        `-- test
            `-- java
                `-- com
                    `-- soebes
                        `-- maui
                            `-- it
                                `-- BitMaskTest.java
    

    The following is needed to make then folders known to the compiler etc.

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>build-helper-maven-plugin</artifactId>
      <version>1.5</version>
      <executions>
        <execution>
          <id>add-test-source</id>
          <phase>process-resources</phase>
          <goals>
            <goal>add-test-source</goal>
          </goals>
          <configuration>
            <sources>
              <source>src/it/java</source>
            </sources>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

    The following is needed to really run the IT's:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-failsafe-plugin</artifactId>
      <version>2.15</version>
      <executions>
        <execution>
          <id>integration-test</id>
          <goals>
            <goal>integration-test</goal>
          </goals>
        </execution>
        <execution>
          <id>verify</id>
          <goals>
            <goal>verify</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    

    This means you can have the integration within the same module which has the disadvantage that running the integration tests use the same resources as the unit tests. A better solution would be to create a separate maven module where you can put the integration tests into the usual folder src/test/java etc. and only configure the maven-failsafe-plugin.

    0 讨论(0)
提交回复
热议问题