测试一般是测试的局部功能,使用时需要自己写个测试相关的spring配置文件,比较费劲,所以常用的是纯配置的方式来实现测试.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
@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); } }