遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

SpringBoot单元测试:@SpringBootTest

接上一篇:SpringBoot整合SSM,https://www.cnblogs.com/uncleyong/p/17065293.html

添加依赖

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

  

编写测试类

package com.qzcsbj.demo;

import com.qzcsbj.demo.mapper.UserMapper;
import com.qzcsbj.demo.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

/**
 * @公众号 : 全栈测试笔记
 * @博客 : www.cnblogs.com/uncleyong
 * @微信 : ren168632201
 * @描述 : <>
 */
@RunWith(SpringRunner.class)  // 底层用的junit,public final class SpringRunner extends SpringJUnit4ClassRunner
@SpringBootTest(classes = SpringbootdemoApplication.class)
public class MyTest {
    @Resource
    UserMapper userMapper;

    @Test
    public void test(){
        List<User> users = userMapper.getUsers();
        for (User user : users) {
            System.out.println(user);
        }
    }
}

 

飘红

 

上面点击后,pom中自动加入了junit依赖

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

 

运行测试类

 

结果

 

【bak】

原文会持续更新,原文地址:https://www.cnblogs.com/uncleyong/p/17065297.html

 

posted @ 2023-01-23 17:14  全栈测试笔记  阅读(230)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end