很多時候在背景接口寫完後,我們都會寫對應的單元測試類去驗證一下接口是否有問題的。但是很多時候在我們用在打包的時候往往會因為這些單元測試類不通過導緻打包失敗的。在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>