spring boot junit-vintage-engine 和 junit-jupiter-engine和以前的junit单元测试,不同,几种方式

springboot

springboot测试工具

junit-vintage-engine 和 junit-jupiter-engine 有什么不同

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

如果你的 Spring 项目使用的新的 Spring Boot 版本的话,你应该默认使用了 JUnit 5 的引擎,因此为了兼容性,你需要在 spring-boot-starter-test 这个 POM 引用的时候将 JUnit 4 的引擎去除掉。

如果自己写的Junit,有什么不同。
<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
 </dependency>
 package com.pctc;


import com.pctc.model.User;
import com.pctc.service.UserService;

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

//一定要有@RunWith
//@RunWith(SpringJUnit4ClassRunner.class)
//@SpringBootTest(classes=SpringbootJspJdbctemplateApplication.class)
@SpringBootTest
//这里一定要有public
public class SpringbootJspJdbctemplateApplicationTests {


    @Autowired
    private UserService userService;
    @Test
    public void testTest(){
        System.out.println("good,idea");
    }

    @Test
    public void userTest(){

        User user=new User();
        user.setName("guo1级1199");
        user.setAge(28);
        userService.createUser(user);
        System.out.println("整合springboot 与junit结束");
    }


}


这个是junit-vintage-engine 和 junit-jupiter-engine可以运行的。但是public警告要改private

​ 区别:自己写的以前单元测试,是public。还有加@RunWith(SpringJUnit4ClassRunner.class),
​ 否则会报空指针异常(在连接数据库的时候)。如果要改自己写单元测试,改包。加runwith,和要public修饰。

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值