简体   繁体   中英

How do I run separate tests?

How do I run a separate folder with the tests in a particular module?

My modules:

    <modules>
        <module>common</module>
        <module>foo</module>
        <module>bar</module>
</modules>

Each module has a 2-3 test folder. I need to run tests folder "utils" in the module bar.

I did limit for the team "MVN test" :

<plugins>

  <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <excludes>
        <exclude>**/utils/**</exclude>
      </excludes>
    </configuration>
    <executions>

      <execution>
        <id>surefire-itest</id>
        <phase>integration-test</phase>
        <goals>
          <goal>test</goal>
        </goals>
        <configuration>
          <excludes>
            <exclude>none</exclude>
          </excludes>
          <includes>
            <include>**/utils/**</include>
          </includes>
        </configuration>
      </execution>
    </executions>
  </plugin>

</plugins>

mvn test - runs all the tests except the "utils". mvn integration-test - runs all the tests.

Now I need to start only "utils". How do I solve this problem?

Option one is to use various profiles to run different surefire exections (and different includes and excludes) via mvn test .

Option two is to use the failsafe plugin with mvn verify . This makes it easy to run unit tests only, or unit tests and integration tests; running integration tests only is possible but awkward.

Don't use the surefire plugin with mvn integration-test . It's usually best not to use mvn integration-test at all. See the introduction to the maven lifecycle for reasons why.

Create another for just the tests in utils and bind it to the phase you want to run them in.

You could possibly group your tests using categories as well if you are using JUnit.

I found a solution to this problem:

mvn test - runs all the tests except the "utils" mvn test -P utilsTest - Only run tests "utils"

<profiles>
    <profile>
        <id>utilsTest</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <exclude>none</exclude>
                        <includes>
                            <include>**/utils/**</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
        <id>test</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <excludes>
                            <exclude>**/utils/**</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM