You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Maven测试IntelliJ Java项目时遇非代码类报错求助

Maven测试非代码报错排查

在IntelliJ中使用Maven运行Java项目测试时,遇到非代码层面的报错,IntelliJ提示:

Please refer to C:\Users\USER\IdeaProjects\testing\target\surefire-reports for the individual test results.

已在pom.xml中添加JUnit 5相关依赖与Surefire插件,配置如下:

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.1.0</version>
        </plugin>
    </plugins>
</build>

解决步骤

  • 查看Surefire报告详情:打开提示路径下的*.txt或*.xml文件,里面会显示具体报错原因(比如依赖版本冲突、测试类路径缺失、JVM参数异常等)
  • 确认版本变量已定义:检查pom.xml是否有<properties>节点声明${junit.jupiter.version},示例:<junit.jupiter.version>5.9.2</junit.jupiter.version>,未定义会导致Maven无法解析依赖版本
  • 清理并重新构建:执行mvn clean清理旧编译文件,再运行mvn test重新执行测试
  • 核对IntelliJ的Maven配置:确保IDE使用项目本地的Maven环境,路径设置在File > Settings > Build, Execution, Deployment > Build Tools > Maven
  • 升级Surefire插件:3.1.0版本存在部分兼容性问题,尝试替换为最新稳定版(如3.2.5)
  • 检查测试类命名:默认情况下Surefire插件只识别以Test结尾的类,若测试类命名不符合规则,需在插件中配置<includes>规则指定测试类范围

内容的提问来源于stack exchange,提问作者geno

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 02:55:05