【问题标题】:How to avoid running surefire unit test with 'mvn site'如何避免使用“mvn site”运行万无一失的单元测试
【发布时间】:2013-11-02 11:41:12
【问题描述】:

每当我运行“mvn site”时,我所有的肯定单元测试都会被执行。有什么办法可以避免在运行 mvn site. 我的 pom 如下所述。我在父项目中使用下面的 pom,所有模块都是这个 pom 的子。

<plugins>
    <!--For Unit tests -->
    <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${surefire.version}</version>
    </plugin>
    <!--For executing Integration tests in integration-test phase -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>${failsafe.version}</version>
    <configuration>
        <excludes>
        <exclude>**/*Test.java</exclude>
        </excludes>
        <includes>
        <include>**/*IT.java</include>
        </includes>
    </configuration>
    <executions>
        <execution>
        <phase>integration-test</phase>
        <goals>
            <goal>integration-test</goal>
            <goal>verify</goal>
        </goals>
        </execution>
    </executions>
    </plugin>
</plugins>
<!--For generating unit and integration test reports -->
<reporting>
    <plugins>
    <plugin>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.7</version>
        <reportSets>
        <reportSet>
            <reports>
            <!--Disable all default reports -->
            </reports>
        </reportSet>
        </reportSets>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>${surefire.version}</version>
        <configuration>
        <aggregate>true</aggregate>
        <linkXRef>true</linkXRef>
        </configuration>
    </plugin>
    </plugins>
</reporting>

【问题讨论】:

标签: maven maven-surefire-plugin


【解决方案1】:

根据插件documentation,使用report-only

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-report-plugin</artifactId>
    <version>${surefire.version}</version>
    <reportSets>
        <reportSet>
            <reports>
                <report>report-only</report>
            </reports>
        </reportSet>
    </reportSets>
</plugin>

surefire-report:report-only:以 html 格式创建格式精美的 Surefire 测试报告。这个目标不运行测试,它只构建报告。这是https://issues.apache.org/jira/browse/SUREFIRE-257的解决方法

【讨论】:

    【解决方案2】:

    试试mvn -DskipTests=true site

    【讨论】:

    • 这很好用,但我想知道为什么“mvn site”只执行单元测试而不执行集成测试?虽然我也可以通过将集成测试目标绑定到我的 pom 中的 阶段来强制它执行集成测试,但是 mvn 站点不会生成故障安全报告,这在我绑定目标的方式上似乎有些问题到阶段。有没有办法在不使用任何 -D 的情况下排除所有测试,或者在生成报告的同时运行单元和整数测试。
    • 为此您需要了解Maven lifecycleintegration-test 不是 site 生命周期的一个阶段。至于“我想知道为什么“mvn site”只执行单元测试而不执行集成测试? - 这不是它在标题和这个问题的描述中所说的。
    • 抱歉,问题不够清晰。但这是我提出这个问题的意图,这样我就不需要每次都明确地说 -DskipTest 。我已经阅读了maven.apache.org/guides/introduction/…,但这并没有说明测试目标与站点生命周期的绑定。你知道为什么 Surefire 测试绑定到 mvn 站点生命周期吗?
    • @MarcelStör Maven 生命周期告诉surefire:test 只绑定到default lifecyletest 阶段,它不绑定到clean 或站点lifecycle 的任何阶段
    猜你喜欢
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 2016-11-22
    • 1970-01-01
    相关资源
    最近更新 更多