SpringBoot write the test class

Guide package

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

  The cursor on the class name, the shortcut Alt + Enter 

 

 

 

 

 

package com.company.mapper;

import com.company.pojo.User;
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;

import static org.junit.jupiter.api.Assertions.*;

//加上这两个注解,运行测试方法的时候就会启动SpringBoot
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserMapperTest {
@Autowired
private UserMapper mapper;

@Test
public void testUser(){
System.out.println(mapper.selectByPrimaryKey(1));
}
}

Guess you like

Origin www.cnblogs.com/zou-rong/p/12566197.html