很多時(shí)候在后臺(tái)接口寫(xiě)完后,我們都會(huì)寫(xiě)對(duì)應(yīng)的單元測(cè)試類(lèi)去驗(yàn)證一下接口是否有問(wèn)題的。但是很多時(shí)候在我們用在打包的時(shí)候往往會(huì)因?yàn)檫@些單元測(cè)試類(lèi)不通過(guò)導(dǎo)致打包失敗的。在idea如果的打包時(shí)不對(duì)單元測(cè)試類(lèi)做特別處理很可能會(huì)出現(xiàn)一下問(wèn)題:
[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
網(wǎng)上對(duì)這樣情況的解決方式很多都是在pom.xml文件中加入:
<!--使單元測(cè)試不影響項(xiàng)目的編譯 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
這里其實(shí)也是可以打包成功的,但是在控制臺(tái)中還是會(huì)輸出單元測(cè)試的錯(cuò)誤信息。因?yàn)樯厦娴呐渲檬潜硎景褑卧獪y(cè)試的錯(cuò)誤忽略掉。對(duì)應(yīng)有強(qiáng)迫癥的一些人來(lái)說(shuō),當(dāng)然是連一點(diǎn)錯(cuò)誤消息都不能出現(xiàn)的。這時(shí)我們可以把上面的配置修改城以下的:
<!--使單元測(cè)試不影響項(xiàng)目的編譯 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip><!--跳過(guò)單元測(cè)試 -->
<!--<testFailureIgnore>true</testFailureIgnore> --><!--這個(gè)網(wǎng)上很多的解決方式是這個(gè),其實(shí)這個(gè),其實(shí)這個(gè)配置后打包還是會(huì)編譯單元測(cè)試類(lèi)的,只是忽略編譯單元測(cè)試類(lèi)的錯(cuò)誤. -->
</configuration>
</plugin>