- 一个正常的SpringBoot使用Junit进行测试其实很简单,只需三步
pom.xml
<dependency>
<!-- this is needed or IntelliJ gives junit.jar or junit-platform-launcher:1.3.2 not found errors -->
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
注入
在test类正常注入
@SpringBootTest
public class TzsbxtApplicationTests {
@Autowired
private NjJxlcService njJxlcService;
调用
@Test
void contextLoads() {
List<NjJxlcEntity> list = njJxlcService.getList();
System.out.println();
}
整个test类代码
import com.lamda.entity.jxlc.NjJxlcEntity;
import com.lamda.service.jxlc.NjJxlcService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class TzsbxtApplicationTests {
@Autowired
private NjJxlcService njJxlcService;
@Test
void contextLoads() {
List<NjJxlcEntity> list = njJxlcService.getList();
System.out.println();
}
}