Maven separate Unit Test and Integration Tests

前端 未结 1 1538
时光取名叫无心
时光取名叫无心 2020-12-23 21:04

UT = Unit Tests IT = Integration Tests. All my Integration test classes are annotated with @Category(IntegrationTest.class)

My goal is:

mvn clean ins

相关标签:
1条回答
  • 2020-12-23 21:49

    The solution is this:

      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>2.19.1</version>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-failsafe-plugin</artifactId>
              <version>2.19.1</version>
            </plugin>
          </plugins>
        </pluginManagement>
       <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>${surefire.skip}</skip>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.12</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    

    This will let you control which is executed.

    running UT and IT's:

    mvn clean verify
    

    running IT's but NOT UT's

    mvn clean verify -Dsurefire.skip=true 
    

    running UT but not IT's:

    mvn clean verify -DskipITs=true 
    

    You need to follow the naming conventions of the plugins which makes life easier.

    Naming conventions for maven-surefire-plugin (unit tests). Naming conventions for maven-failsafe-plugin (integration tests).

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