(1)缺啥bean自己做。
@TestConfiguration public class BeanConfig {
@Bean public XXX createXXX(){ return new XXX(); }
(2)没有启动类,就写一个
@SpringBootConfiguration @EnableAutoConfiguration @ComponentScan(basePackages = {"cn.xxx"}) public class xxxApplication { .... }
(3)主测试类:
//@RunWith(SpringJUnit4ClassRunner.class) @Import({dataSourceConfig.class,BeanConfig.class}) @RunWith(SpringRunner.class) @SpringBootTest(classes = xxxApplication.class,webEnvironment = SpringBootTest.WebEnvironment.NONE ) @Transactional(transactionManager = "transactionManagerXXX") @Rollback(value=false) //@ContextConfiguration( classes = {xxxApplication.class}) //@PropertySource(value={"classpath:db.properties","classpath:xxxx.properties"}) @PropertySources({ @PropertySource("classpath:db.properties"), @PropertySource("classpath:xxxx.properties") }) //@PropertySource("classpath:db.properties") public class DbTestBase { ..}
定义的类需要@Import进来。
(4)测试类继承主测试类即可。
|