SpringBoot单元测试

引入依赖

  引入spring-boot-starter-test依赖,其中包含了junit,所以不需要额外引入junit。

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

 

测试  

  在测试类上面增加@SprintBootTest注解和@RunWith注解(@RunWith由junit提供),并且在@RunWith中指定SpringRunner即可,如下所示:

package cn.ganlixin.business;


import cn.ganlixin.model.bo.UserInfoBO;
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;

@SpringBootTest
@RunWith(SpringRunner.class)
public class UserServiceTest {

    @Resource
    private UserService userService;

    @Test
    public void testSelectAll() {
        List<UserInfoBO> allUser = userService.getAllUser();
    }
}

  

   原文链接:https://www.cnblogs.com/-beyond/p/13675358.html

 

posted @ 2020-09-15 20:46  寻觅beyond  阅读(348)  评论(0编辑  收藏  举报
返回顶部