maven打包報錯,設置跳過單元測試解決

很多時候在后臺接口寫完后,我們都會寫對應的單元測試類去驗證一下接口是否有問題的。但是很多時候在我們用在打包的時候往往會因為這些單元測試類不通過導致打包失敗的。在idea如果的打包時不對單元測試類做特別處理很可能會出現一下問題:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project project-service: There are test failures.
[ERROR] 
[ERROR] Please refer to E:\IdeaProjects\project\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

網上對這樣情況的解決方式很多都是在pom.xml文件中加入:

<!--使單元測試不影響項目的編譯 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
<testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>

這里其實也是可以打包成功的,但是在控制臺中還是會輸出單元測試的錯誤信息。因為上面的配置是表示把單元測試的錯誤忽略掉。對應有強迫癥的一些人來說,當然是連一點錯誤消息都不能出現的。這時我們可以把上面的配置修改城以下的:


            <!--使單元測試不影響項目的編譯 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip><!--跳過單元測試 -->
                    <!--<testFailureIgnore>true</testFailureIgnore> --><!--這個網上很多的解決方式是這個,其實這個,其實這個配置后打包還是會編譯單元測試類的,只是忽略編譯單元測試類的錯誤. -->
                </configuration>
            </plugin>
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容