解决springboot 2.2.5 单元测试类的报错

Posted 做人如水,做事如山

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决springboot 2.2.5 单元测试类的报错相关的知识,希望对你有一定的参考价值。

类不存在

 

 原因分析  是junit5升级了 框架没有兼容

解决办法

1 改写pom.xml

<!--测试模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>1.0.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.0.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>5.5.2</version>
            <scope>test</scope>
        </dependency>

测试类

org.junit.jupiter.api.Test;

 替换成

import org.junit.Test;

最后的测试单元类

package com.wechat.chat;

import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class ChatApplicationTests {

    @Test
    public void contextLoads() {
    }

}

 

以上是关于解决springboot 2.2.5 单元测试类的报错的主要内容,如果未能解决你的问题,请参考以下文章