Spring boot implements unit test process analysis through JUnit

Time:2020-5-28

This article mainly introduces spring boot’s implementation of unit test process analysis through JUnit. The example code in this article is very detailed, which has a certain reference learning value for everyone’s study or work. You can refer to the following for friends who need it

1. Need to pom.xml Introducing spring boot starter test in


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

2. Unit test code

Two key notes

@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 (set size:+ list.size ());
	}
}

The above is the whole content of this article. I hope it will be helpful for your study, and I hope you can support developepaer more.

Recommended Today

Analysis of super comprehensive MySQL statement locking (Part 1)

A series of articles: Analysis of super comprehensive MySQL statement locking (Part 1) Analysis of super comprehensive MySQL statement locking (Part 2) Analysis of super comprehensive MySQL statement locking (Part 2) Preparation in advance Build a system to store heroes of the Three KingdomsheroTable: CREATE TABLE hero ( number INT, name VARCHAR(100), country varchar(100), PRIMARY […]