spring 整合Junit学习

时间:2022-01-04 16:26:18

测试一般是测试的局部功能,使用时需要自己写个测试相关的spring配置文件,比较费劲,所以常用的是纯配置的方式来实现测试.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={CustomerServiceTest.class})
@Configuration
@ComponentScan(basePackages={"com.itheima"})
public class CustomerServiceTest { @Autowired
private ICustomerService customerService; @Test
public void testFindAll(){
customerService.findAllCustomer();
} @Test
public void testSave(){
Customer c = new Customer();
c.setCustName("传智学院 ");
customerService.saveCustomer(c);
}
}

测试的demo