1.需要在pom.xml中引入spring-boot-starter-test

 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
</dependency>
4.Spring-Boot中基于Junit的单元测试

2.单元测试代码

两个关键的注解

@RunWith(SpringRunner.class)

@SpringBootTest

package com.niugang.test;

import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.junit4.SpringRunner;

import com.niugang.entity.User;

import com.niugang.service.UserService;

@RunWith(SpringRunner.class)

@SpringBootTest

public class TestUser {

  @Resource

  private UserService userService;

  @Test

public void test1(){

  List<User> list = userService.queryList(null);

  System.out.println("集合大小:"+list.size());

}



}

 

4.Spring-Boot中基于Junit的单元测试

注意不能不建包,直接写测试类

微信公众号

                          

相关文章:

  • 2022-12-23
  • 2021-09-08
  • 2021-06-15
  • 2021-07-16
  • 2022-02-27
  • 2021-11-15
猜你喜欢
  • 2021-07-27
  • 2021-12-23
  • 2022-12-23
  • 2021-07-24
  • 2021-06-20
相关资源
相似解决方案