sptingboot本地测试
1、springboot使用junit测试,必须引入相关依赖
spring-boot-starter-test
<!-- 引入test支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- 这个一定要有,只在测试上面部署,不在生产上有-->
</dependency>
2、再src/test/java中创建测试类
@RunWith(SpringRunner.class)//启动工厂
//@ContextConfiguration//指定工厂得配置文件
@SpringBootTest(classes = Application.class) //但是这回没有了工厂得配置文件,所以这回不需要用@ContextConfiguration//指定工厂得配置文件,所以把这个去掉
public class BasicTest {
@Autowired
private UserService userService;
@Test
public void testFindAll(){
userService.findAll().forEach(user-> System.out.println(user));
}
}
along

浙公网安备 33010602011771号