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
如需转载,请注明文章出处,谢谢!!!