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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容