簡體   English   中英

如何阻止 Maven 運行 TEST 兩次?

[英]How can I stop maven from running TEST twice?

我有一個包含大約 5000 個測試用例的大項目。 運行mvn clean install時,它將運行test目標兩次(一次作為安裝的一部分,第二次作為surefire插件的一部分)。

為什么它需要第二次運行test 並且有沒有強制surefire使用test目標結果而不是重新調用它自己的? 我認為這是浪費時間和機器資源,尤其是最近第二輪運行test導致PermGen構建錯誤,無論我向 maven runner 注入多少堆,它仍然在第二輪測試中死亡。

這是我的萬無一失的插件配置:

 <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <executions>
       <execution>
         <id>default-test</id>
         <phase>test</phase>
         <goals>
             <goal>test</goal>
         </goals>
         <configuration>
            <parallel>classes</parallel>
            <threadCount>3</threadCount>
         </configuration>
      </execution>
   </executions>
</plugin>

有沒有辦法調整插件以更好地處理機器資源?

這是執行的完整默認 Maven 配置文件:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                    <manifestEntries>
                        <Build-Number>${build.number}</Build-Number>
                        <Job-Name>${job.name}</Job-Name>
                        <Build-Url>${build.url}</Build-Url>
                        <Git-Commit>${git.commit}</Git-Commit>
                        <Git-Branch>${git.branch}</Git-Branch>
                        <Timestamp>${maven.build.timestamp}</Timestamp>
                        <StyleGuide-Version>${styleguide.version}</StyleGuide-Version>
                    </manifestEntries>
                </archive>
                <warName>pss</warName>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.cj.jshintmojo</groupId>
            <artifactId>jshint-maven-plugin</artifactId>
            <version>1.3.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>lint</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <options>maxparams:5,camelcase,eqeqeq,forin,immed,latedef,noarg,noempty,nonew,expr</options>
                <directories>
                    <directory>src/main/webapp/js/page</directory>
                </directories>
                <excludes>
                    <exclude>src/main/webapp/js/page/marketingPreferences.js</exclude>
                    <exclude>src/main/webapp/js/page/changeCarParkingDetails.js</exclude>
                    <exclude>src/main/webapp/js/page/angularjs-app.js</exclude>
                    <exclude>src/main/webapp/js/page/content-cover.js</exclude>
                    <exclude>src/main/webapp/js/page/amendmentConfirm.js</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.lesscss</groupId>
            <artifactId>lesscss-maven-plugin</artifactId>
            <version>1.3.3</version>
            <executions>
                <execution>
                    <id>bingleless</id>
                    <configuration>
                        <sourceDirectory>${project.basedir}/src/main/webapp/app-resources/</sourceDirectory>
                        <outputDirectory>${project.basedir}/src/main/webapp/app-resources/</outputDirectory>
                        <includes>
                            <include>**\/policy-self-service\/**\/*pss-sg.less</include>
                        </includes>
                        <compress>true</compress>
                    </configuration>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <excludes>
                    <exclude>**/*.min.js</exclude>
                    <exclude>**/*.min.css</exclude>
                    <exclude>**/style-guide/**</exclude>
                    <exclude>**/generated/**</exclude>
                    <exclude>**/app-resources/common/**</exclude>
                    <exclude>**/app-resources/bower_components/**</exclude>
                    <exclude>**/app-resources/policy-self-service/**</exclude>
                </excludes>
                <nosuffix>true</nosuffix>
                <jswarn>false</jswarn>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <configuration>
                <logViolationsToConsole>true</logViolationsToConsole>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven-surefire-plugin.version}</version>
            <configuration>
                <parallel>classes</parallel>
                <threadCount>3</threadCount>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>${maven-surefire-report-plugin.version}</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>report-only</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我認為pom.xml中的<execution>會導致第二次測試運行。 除了測試階段的默認目標之外,Maven 將其視為另一個執行目標。

由於maven-surefire-plugin是 Maven 中默認用於測試階段的插件,您只需要在<execution>之外提供<configuration>部分。 修改你的pom.xml如下

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
        <parallel>classes</parallel>
        <threadCount>3</threadCount>
    </configuration>
  </plugin>
</plugins>

如果在您的 pom 中同時存在 cobertura 和 surefire 插件,則測試將執行兩次。 為了避免在 cobertura 插件中將執行階段添加為 none,如下所述:

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>none</phase>
                </execution>
            </executions>
</plugin>

就我而言,我發現:
因為使用了maven-surefire-plugin rerunFailingTestsCount -plugin 的 rerunFailingTestsCount ,所以如果測試失敗,會再次運行。

順便一提:
我反對嘗試多次重新運行不穩定的測試直到成功,相反我們可以解決它的根本原因。

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        ...
        <!-- Workaround to make builds more stable while having flaky tests -->
        <rerunFailingTestsCount>1</rerunFailingTestsCount>
    </configuration>
</plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM