springboot项目,对service层进行单元测试的步骤:
1.添加相关依赖,
2.在测试类添加两个注解:@RunWith(SpringJUnit4ClassRunner.class),
@SpringBootTest(classes = ChargerOperateApplication.class),
添加@Before\@After,注入自己的bean
3.编写测试代码。
具体如下:
1.添加相关依赖,
<!-- 单元测试依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>