【问题标题】:Maven failsafe doesn't read environmentVariables config for integration testsMaven 故障安全不读取 environmentVariables 配置以进行集成测试
【发布时间】:2018-06-02 14:09:23
【问题描述】:


我的 Maven 构建包含单元和集成测试执行作为 2 个独立的配置文件,使用 Jacoco 进行代码覆盖。
我在使用 failsafe 插件时遇到了几个问题,需要一个方向来寻找解决方案。我已经浏览了大量可用的内容,但仍然无法解决问题。

  1. <environmentVariables> 不适用于故障保护,但它适用于万无一失。我已经尝试了<systemProperties><systenPropertiesVariables><properties> 的所有内容;但似乎没有一个可以为我的集成测试用例设置环境变量。
  2. 使用<excludes> 的测试用例排除对故障安全不起作用;和万无一失一样。

我的故障安全配置是:

<profile>
    <id>it-coverage</id>
    <build>
        <plugins>
            <!-- MAVEN Failsafe plugin. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20.1</version>
                <configuration>
                    <argLine>${failsafeArgLine}</argLine>
                    <environmentVariables>
                        <config>config/preferences.xml</config>
                        <log4jproperties>config/log4j.properties</log4jproperties>
                        <jacoco-agent.destfile>target/it-jacoco.exec</jacoco-agent.destfile>
                    </environmentVariables>
                    <excludes>
                        <exclude>**/*UTest.java</exclude>
                    </excludes> 
                    <includes>
                        <include>**/*ITest.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

【问题讨论】:

  • 第 2 点现已解决。我在故障安全配置文件中添加了 Surefire-plugin 并标记为 true

标签: maven maven-surefire-plugin maven-failsafe-plugin


【解决方案1】:

好吧,我的问题已经解决了。 我将 surefire-pluginfailsafe-plugin 一起添加到我的集成配置文件中,一切都开始到位。

以下是对我有用的配置。

<profile>
    <id>it-coverage</id>
    <build>
        <plugins>
            <!-- MAVEN Failsafe plugin. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20.1</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- Sets the VM argument line used when unit tests are run. -->
                    <argLine>${failsafeArgLine}</argLine>
                    <systemPropertyVariables>
                        <config>${config.preferences}</config>
                        <log4jproperties>${config.log4jproperties}</log4jproperties>
                        <!-- <jacoco-agent.destfile>target/it-jacoco.exec</jacoco-agent.destfile> -->
                        <jacoco-agent.destfile>${sonar.jacoco.itReportPath}</jacoco-agent.destfile>
                    </systemPropertyVariables>
                    <includes>
                        <include>**/*ITest.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>

            <!-- MAVEN Jacoco plugin -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <configuration>
                    <excludes>
                        <exclude>**/*UTest.java</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution> 
                        <id>default-instrument</id>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-restore-instrumented-classes</id>
                        <goals>
                            <goal>restore-instrumented-classes</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <classifier>runtime</classifier>
            <version>${jacoco.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</profile>

【讨论】:

  • 这并没有真正回答如何获得故障安全以读取环境变量,对吧?您只是最终使用了系统属性。看起来可以通过 元素或 元素传递系统属性,但不读取/使用环境变量。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-15
  • 2012-08-21
  • 1970-01-01
  • 2017-12-12
相关资源
最近更新 更多