这是我在使用springboot整合Junit的时候遇到的坑
1.在pom.xml中添加junit环境的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
2.在src/test/java下建立测试类
例:
@RunWith(value = SpringJUnit4ClassRunner.class)
@SpringBootTest(classes={Demo.class}) // **注意:启动类为自己编写的(这是个坑)**
public class serviceTest {
@Autowired
private serviceImpl serviceimpl;
@Test
public void testAdd() {
this.serviceimpl.add();
}
}
3.自己编写的启动类
@SpringBootApplication
public class Demo {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(De