在Springboot项目中集成单元测试及其的简单,首先先在pom文件中添加如下依赖:
?<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>?
然后建立单元测试类,如下示例:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class UserTest {@Autowiredprivate UserService userService;@Testpublic void myTest() {userService.get();}}
其中Application.class需要替换成自己的项目的启动类。然后run当前的类即可。