maven项目test报错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin

今天导入一个原来的maven项目,项目上右键运行JUnit Test,可以通过测试,但是运行mvn test时,报错:
Results :

Failed tests: twm.camera.core.OutPutStringTest.testPrint(): org/junit/Assert

Tests run: 2, Failures: 1, Errors: 0, Skipped: 0

[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 2.729 s
[INFO] Finished at: 2017-09-17T09:54:47+08:00
[INFO] Final Memory: 7M/19M
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project firstexm: There are test failures.
[ERROR]
[ERROR] Please refer to D:\workspace\mars\core\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

查阅了一下很早之前的资料,发现将测试类public class OutPutStringTest改为抽像类public abstract class OutPutStringTest后,去行mvn test即可通过。
没花时间去深究这类应用问题,谨此记录一下。有知道原因的可以留言。

### IDEA 中创建 Maven Web 项目时遇到 `Failed to execute goal` 错误的解决方案 当在 IntelliJ IDEA 中创建并尝试构建 Maven Web 项目时,如果遇到了类似于 `Failed to execute goal org.apache.maven.plugins` 的错误提示,这通常意味着某些插件配置不正确或缺少必要的依赖项。 #### 修改 pom.xml 文件中的 Surefire 插件配置 为了修复此问题,在项目的根目录下打开 `pom.xml` 文件,并确保 `<build>` 节点内包含了如下所示的 Maven Surefire Plugin 配置: ```xml <build> <plugins> <!-- 添加或更新 surefire plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build> ``` 上述代码片段通过设置 `<skipTests>true</skipTests>` 来跳过测试阶段,从而避免因测试失败而导致整个构建过程终止[^2]。 #### 更新本地仓库索引 有时由于网络原因或其他因素可能导致本地缓存的数据损坏。可以尝试清理本地 Maven 缓存来解决问题: - 打开命令行工具; - 输入命令 `mvn clean install -U` 强制刷新远程资源到本地仓库; #### 检查 IDE 设置与环境变量 确认当前使用的 JDK 版本是否满足项目需求以及是否已正确安装 JRE/JDK 并将其路径添加至系统的 PATH 环境变量中。另外还需验证 Idea 自身所指向的 SDK 是否准确无误。 #### 使用合适的生命周期阶段执行操作 对于初次导入的新工程来说,默认情况下可能会自动触发一些不必要的目标(goals),比如运行单元测试等。可以通过指定更恰当的目标来进行编译工作,例如仅使用 `package` 或者 `compile` 命令代替默认的 `install`。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值