Spring boot 1.40
JUnit 4
需要依赖包 spring-boot-starter-test、spring-test
建立class,加上如下注解,即可进行单元测试,别的帖子里说要加@WebAppConfiguration,但是在实际测试中,我报错了,无法加载service bean出来
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
右键,run as junit test
即可完成测试