Junit单元测试的maven设置

maven

官方文档: https://maven.apache.org/surefire/maven-surefire-plugin/usage.html

maven是通过插件 maven-surefire-plugin 来执行单元测试

指定test文件的之间的执行顺序

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven.surefire.version}</version>
    <configuration>
        <runOrder>alphabetical</runOrder><!-- 按文件字母顺序排序 -->
    </configuration>
</plugin>

并行执行ut

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.version}</version>
        <configuration>
          <parallel>methods</parallel>
          <threadCount>10</threadCount>
<!--      <forkCount>1</forkCount>-->
<!--      <parallel>none</parallel>&lt; 禁用并行执行-->
        </configuration>
      </plugin>

跳过test

  • 命令行
mvn install -Dmaven.test.skip=true
  • 默认设置跳过test
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.version}</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>

重跑失败的ut

mvn -Dsurefire.rerunFailingTestsCount=2 test
posted @ 2023-11-16 09:20  Eiffelzero  阅读(508)  评论(0)    收藏  举报