maven:如何通过命令行选项跳过某些项目中的测试? [英] maven: How can I skip test in some projects via command line options?

查看:490
本文介绍了maven:如何通过命令行选项跳过某些项目中的测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的maven项目中,我有许多模块.是否可以通过命令行选项关闭某些模块的运行单元测试?

In my maven project I have a number of modules. Is it possible to turn off running unit test for some modules via command line options?

我的项目大约需要15分钟才能完成所有单元测试.我想通过仅在我正在处理的模块中运行单元测试来加快总体构建速度.我不想进入并编辑每个单独的pom.xml来实现此目的.

My project takes about 15 mins to run through all unit tests. I would like to speed up the overall build by running just the unit tests in the module I am working on. I do not want to go in and edit each individual pom.xml to achieve this.

我尝试了此处概述的解决方案:可以我是通过maven运行特定的testng测试组的吗?但是,结果是我要跳过的模块中有很多测试失败.我想组"与模块的概念不同吗?

I have tried a solution outlined here: Can I run a specific testng test group via maven? However the result is a lot of test failures in modules that I want to skip. I suppose 'group' is not the same concept of module?

推荐答案

要打开和关闭整个项目的单元测试,请使用

To toggle unit tests on and off for an entire project use Maven Surefire Plugin's capability of skipping tests. There is a drawback with using skipTests from the command line. In a multi-module build scenario, this would disable all tests across all modules.

如果您需要对模块的测试子集进行更精细的控制,请使用

If you need more fine grain control of running a subset of tests for a module, look into using the Maven Surefire Plugin's test inclusion and exclusion capabilities.

要允许命令行替代,请在配置Surefire插件时使用POM属性.以下面的POM段为例:

To allow for command-line overrides, make use of POM properties when configuring the Surefire Plugin. Take for example the following POM segment:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <excludes>
            <exclude>${someModule.test.excludes}</exclude>
          </excludes>
          <includes>
            <include>${someModule.test.includes}</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <properties>
    <someModule.skip.tests>false</someModule.skip.tests>
    <skipTests>${someModule.skip.tests}</skipTests>
    <someModule.test.includes>**/*Test.java</someModule.test.includes>
    <someModule.test.excludes>**/*Test.java.bogus</someModule.test.excludes>
  </properties>

使用上述POM,您可以通过多种方式执行测试.

With a POM like the above you can execute tests in a variety of ways.

  1. 运行所有测试(以上配置包括所有**/* Test.java测试源文件)

mvn test

  1. 跳过所有模块中的所有测试

mvn -DskipTests=true test

  1. 跳过所有针对特定模块的测试

mvn -DsomeModule.skip.tests=true test

  1. 仅对特定模块运行某些测试(此示例包括所有**/* IncludeTest.java测试源文件)

mvn -DsomeModule.test.includes="**/*IncludeTest.java" test

  1. 排除特定模块的某些测试(此示例排除了所有**/* ExcludeTest.java源文件)

mvn -DsomeModule.test.excludes="**/*ExcludeTest.java" test

这篇关于maven:如何通过命令行选项跳过某些项目中的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆