org.apacmaven-surefire-plugin:2.22.1:test (default-test) on project spring: There are test failures.

这篇博客讲述了在IDEA中遇到项目打包时测试失败的问题,提供了两种解决方法:一是通过在pom.xml中添加maven-surefire-plugin依赖跳过测试;二是使用IDEA的Maven工具跳过测试后打包。同时建议检查逻辑和配置文件是否正确,并在解决问题后可移除临时添加的配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


IDEA中报错及截图:
Failed to execute goal org.apache.maven-surefire-plugin:2.22.1:test (default-test) on project spring: There are test failures.

在这里插入图片描述
问题原因:在项目打包时,报测试失败。直接跳过测试打包即可。

问题解决方法:

1、方法一:添加依赖跳过测试并打包
在maven依赖pom.xml 插件中添加一个maven-surefire-plugin依赖即可(我演示的项目是用webapp骨架生成的)

        <plugin>
          <groupId>org.apache.maven.plugins<
完全的报错如下[INFO] Results: [INFO] [ERROR] Errors: [ERROR] HospitalApplicationTests.contextLoads » IllegalState Failed to load ApplicationContext for [WebMergedContextConfiguration@100c8b75 testClass = com.example.hospital.HospitalApplicationTests, locations = [], classes = [com.example.hospital.HospitalApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@14fc5f04, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@333d4a8c, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@1b1cfb87, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@475c9c31, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@5276d6ee, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@1c9b0314, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@95981886], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null] [INFO] [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.712 s [INFO] Finished at: 2025-05-16T19:37:13+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.3:test (default-test) on project hospital: [ERROR] [ERROR] See C:\D\java\project\spring\hospital\target\surefire-reports for the individual test results. [ERROR] See dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream. [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
最新发布
05-17
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值