CodeZLei

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::

测试一般是测试的局部功能,使用时需要自己写个测试相关的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

 

posted on 2018-07-17 09:43  CodeZLei  阅读(155)  评论(0编辑  收藏  举报