[雷]单元测试报错--Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test

本文档详细记录了在SpringBoot项目中集成Mybatis-Plus进行单元测试时遇到的初始化错误,涉及构造器、公共访问权限及maven-surefire-plugin的配置。通过添加maven-surefire-plugin并调整相关设置,成功解决了测试运行问题。
部署运行你感兴趣的模型镜像

项目场景:

SpringBoot集成Mybatis-Plus时,进行单元测试时报错


问题描述:

package com.mybatisplusstudty.mapper;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @Description:
 * @Author: 涛涛 *^*
 * @Date: 2021/1/7 15:13
 */
@SpringBootTest
class UserMapperTest {

    @Autowired
    private UserMapper userMapper;

    @Test
    void test() {
        userMapper.selectList(null).forEach(System.out::println);
    }


}
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.qcsoft.qcofflinereport.QcOfflineReportApplicationTests
[ERROR] Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 0.136 s <<< FAILURE! - in com.qcsoft.qcofflinereport.QcOfflineReportApplicationTests
[ERROR] initializationError(com.qcsoft.qcofflinereport.QcOfflineReportApplicationTests)  Time elapsed: 0.017 s  <<< ERROR!
java.lang.Exception: The class com.qcsoft.qcofflinereport.QcOfflineReportApplicationTests is not public.

[ERROR] initializationError(com.qcsoft.qcofflinereport.QcOfflineReportApplicationTests)  Time elapsed: 0 s  <<< ERROR!
java.lang.Exception: Test class should have exactly one public constructor

[ERROR] initializationError(com.qcsoft.qcofflinereport.QcOfflineReportApplicationTests)  Time elapsed: 0 s  <<< ERROR!
java.lang.Exception: Method contextLoads() should be public

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR] com.qcsoft.qcofflinereport.QcOfflineReportApplicationTests.initializationError(com.qcsoft.qcofflinereport.QcOfflineReportApplicationTests)
[ERROR]   Run 1: QcOfflineReportApplicationTests.initializationError »  The class com.qcsoft.qc...
[ERROR]   Run 2: QcOfflineReportApplicationTests.initializationError »  Test class should have ...
[ERROR]   Run 3: QcOfflineReportApplicationTests.initializationError »  Method contextLoads() s...
[INFO] 
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.250 s
[INFO] Finished at: 2020-03-30T16:11:20+08:00
[INFO] Final Memory: 28M/437M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project qc-offline-report: There are test failures.
[ERROR] 
[ERROR] Please refer to D:\fzh\qc-offline-report\target\surefire-reports for the individual test results.
[ERROR] Please refer to 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

解决方案:

.解决方案:在原来的maven依赖插件中新加一个maven-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>

添加之后的pom文件

 <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </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>

您可能感兴趣的与本文相关的镜像

Llama Factory

Llama Factory

模型微调
LLama-Factory

LLaMA Factory 是一个简单易用且高效的大型语言模型(Large Language Model)训练与微调平台。通过 LLaMA Factory,可以在无需编写任何代码的前提下,在本地完成上百种预训练模型的微调

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小七会喷火

小七想要bi

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值