简体   繁体   English

如何运行单独的测试?

[英]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. 每个模块都有一个2-3个测试文件夹。 I need to run tests folder "utils" in the module bar. 我需要在模块栏中运行测试文件夹“ utils”。

I did limit for the team "MVN test" : 我为团队“ MVN测试”做了限制:

<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 test-运行除“ utils”以外的所有测试。 mvn integration-test - runs all the tests. mvn integration-test-运行所有测试。

Now I need to start only "utils". 现在,我只需要启动“ 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 . 选项1是使用各种配置文件通过mvn test运行不同的surefire执行(以及不同的包含和排除)。

Option two is to use the failsafe plugin with mvn verify . 选项二是将故障安全插件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 . 不要将surefire插件与mvn integration-test It's usually best not to use mvn integration-test at all. 通常最好不要使用mvn integration-test See the introduction to the maven lifecycle for reasons why. 有关原因,请参见Maven生命周期简介

Create another for just the tests in utils and bind it to the phase you want to run them in. 为utils中的测试创建另一个,并将其绑定到您要在其中运行的阶段。

You could possibly group your tests using categories as well if you are using JUnit. 如果您使用的是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" mvn测试-运行除“ utils”以外的所有测试mvn测试-P utilsTest-仅运行测试“ 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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