• SpringBoot入门十(整合之Junit测试)



    目标:在spring Boot项目中使用Junit进行单元测试UserService的方法


    分析:
    1.添加启动器依赖spring-boot-starter-test
    2.编写测试类测试

    =====

    1.添加启动器依赖spring-boot-starter-test

            <!--添加测试依赖启动器-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
            </dependency>

    2.编写测试类测试

    package com.cc8w.home.service;
    
    import com.cc8w.com.cc8w.entity.User;
    import com.cc8w.home.mapper.UserMapper;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class UserServiceTest {
        @Autowired
        private UserService userService;
    
        @Test
        public void queryById(){
            userService.queryById(1);
        }
        @Test
        public void saveUser(){
            userService.saveUser(new User());
    
        }
    
    }
  • 相关阅读:
    Docker核心技术之镜像(8)
    简单的自定义函数(7)
    存储过程游标的使用(6)
    存储过程循环语句(5)
    存储过程条件语句(4)
    存储过程的参数(3)
    存储过程的变量(2)
    一个简单的存储过程(1)
    Docker加速器配置(7)
    单表、多表查询
  • 原文地址:https://www.cnblogs.com/fps2tao/p/13824509.html
Copyright © 2020-2023  润新知