Maven failsafe不读取环境变量配置进行集成测试

问题描述 投票:1回答:1

My Maven构建包括单元和集成测试执行,作为两个独立的配置文件与Jacoco进行代码覆盖。 我有一些故障安全插件的问题,需要一个方向来寻找解决方案。我已经通过大量可用的内容进行了讨论,但还无法解决问题。

  1. <environmentVariables>不适用于故障保险,而它肯定会起作用。我尝试了所有来自<systemProperties><systenPropertiesVariables><properties>;但似乎没有人为我的Integrations测试用例设置环境变量。
  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>
maven maven-surefire-plugin maven-failsafe-plugin
1个回答
0
投票

好吧,我的问题得到了解决。我将surefire-plugin添加到我的集成配置文件以及failsafe-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>
© www.soinside.com 2019 - 2024. All rights reserved.