当前位置: 代码迷 >> 综合 >> SpringBoot集成单元测试
  详细解决方案

SpringBoot集成单元测试

热度:20   发布时间:2023-10-17 09:44:14.0

    在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当前的类即可。