首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单元测试在执行mvn安装时执行两次

单元测试在执行mvn安装时执行两次
EN

Stack Overflow用户
提问于 2020-05-30 00:59:38
回答 1查看 276关注 0票数 0

单元测试将被执行两次。

当我从pom中的maven插件中删除目标报告和阶段准备包时,测试会执行一次,但随后在控制台中不会生成覆盖率。

但是当我在pom中添加来自maven插件的目标报告和阶段准备包时,我在控制台中获得了覆盖范围,但是单元测试被执行了两次。

我需要在我的pom中有目标报告和阶段准备包,以便获得覆盖率,但只需要运行一次测试用例。让测试用例也只执行一次的方法是什么?

代码语言:javascript
复制
<plugins>
        <!-- Configure maven-compiler-plugin to use the desired Java version -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <!-- Use build-helper-maven-plugin to add Scala source and test source
            directories -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/main/scala</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/test/scala</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!-- Use scala-maven-plugin for Scala support -->
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.2.2</version>
            <executions>
                <execution>
                    <goals>
                        <!-- Need to specify this explicitly, otherwise plugin won't be called
                            when doing e.g. mvn compile -->
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- disable surefire -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.7</version>
            <configuration>
           <skipTests>true</skipTests>

         </configuration>
        </plugin>

        <plugin>
            <groupId>org.scoverage</groupId>
            <artifactId>scoverage-maven-plugin</artifactId>
            <version>${scoverage.plugin.version}</version>
            <configuration>
                <aggregate>true</aggregate>
                <highlighting>true</highlighting>
                <scalacPluginVersion>1.3.0</scalacPluginVersion>
                <minimumCoverage>30</minimumCoverage>
                <failOnMinimumCoverage>false</failOnMinimumCoverage>
            </configuration>

                            <executions>
                                <execution>
                                    <goals>
                                        <goal>report</goal> <!-- or integration-check -->
                                    </goals>
                                    <phase>prepare-package</phase> <!-- or any other phase -->

                              </execution>
                            </executions>

        </plugin>
        <!-- enable scalatest -->
        <plugin>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <version>1.0</version>
            <configuration>
                <argLine>
                    -javaagent:"${settings.localRepository}"/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                </argLine>

                <forkMode>once</forkMode>

                <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                <junitxml>.</junitxml>
                <filereports>WDF TestSuite.txt</filereports>
                <!-- The scalatest-maven-plugin seems broken for the spanScaleFactor,
                    so pass it via system property, instead -->
                <!-- <spanScaleFactor>${scalatest.span.scale.factor}</spanScaleFactor> -->
                <systemProperties>
                    <spanScaleFactor>${scalatest.span.scale.factor}</spanScaleFactor>
                </systemProperties>

            </configuration>
            <executions>
                <execution>
                    <id>test</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>enter code here
EN

回答 1

Stack Overflow用户

发布于 2020-10-10 04:18:58

你需要做两件事:

  1. 在‘scoverage maven-plugin’插件的‘配置’部分添加下面一行。

skipTests=false

  1. 在根pom.xml中设置以下属性

真正的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62091062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档