spring整合junit抽离重复部分

/**
 * 业务层测试
 * spring整合junit抽离重复部分
 * 		ApplicationContext ac = new AnnotationConfigApplicationContext(factory.class);
		ICustomerService cs = (ICustomerService) ac.getBean("customerService");
 * 第一步导入spring-test-4.3.2.RELEASE
 * 
 * 第二步使用@RunWith,把原有的main函数替换掉换成spring提供的
 * 			要更换的类名:SpringJunit4ClassRunner
 * 第三部使用spring提供的注解告知spring,配置文件或者注解类所在的位置--->             
 * @ContextConfiguration
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={factory.class})
public class test {
	@Autowired
	private ICustomerService cs;
	@Test
	public void findall(){
		List<Customer> list = cs.findAllCustomer();
		for(Object o : list){
			System.out.println(o);
		}
	}
	
}

猜你喜欢

转载自blog.csdn.net/v_nbsp/article/details/82467156