junit4和junit5区别

是不是报错

TestEngine with ID ‘junit-vintage‘ failed to discover tests

junit-vintage-engine 是 JUnit 4 中使用的测试引擎。
junit-jupiter-engine 是 JUnit 5 中使用的测试引擎。

import org.junit.Test; //我是4
import org.junit.jupiter.api.Test ; //这里是5

springboot 2.1 之前

使用 junit5 需要配合@ExtendWith(SpringExtension.class)才能正常工作的

springboot 2.1 .*

2.1之后的版本 @SpringBootTest 的已经组合了@ExtendWith(SpringExtension.class),因此,无需在进行该注解的使用了,进一步简化。

springboot <2.4

2.4之前要用junit5,需要去除junit-vintage-engine
(如果报estEngine with ID ‘junit-vintage’ failed to discover tests)

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

springboot >2.4

默认JUnit5,如果要用4,需要加junit包

         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.3.12.RELEASE</version>
            <scope>test</scope>
        </dependency>

的时候可以用@RunWith(SpringRunner.class)
如果版本大于2.4,则必须配置junit,否则无法使用@RunWith(SpringRunner.class)和org.junit.Assert.*

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.4.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值