SpringBoot 单元测试
1. 如果springBoot 工程有 启动类,
class Application 是该工程的启动类,同时要确定该启动类扫描的包的路径
则
在测试类上添加注解:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
2.SpringBoot没有启动类
2.1 添加 TestConfig.class
@Configuration
@ComponentScan("com.**.**")
@PropertySource("classpath:application.properties")
public class TestConfig {
}
然后编写测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={TestConfig.class})
public class ServiceTest{
}

浙公网安备 33010602011771号