** * 使用junit单元测试:测试配置 * * Spring整合junit * 1.导入spring整合junit的jar(坐标) * 2.使用junit提供的一个注解把原有的main方法替换了,替换成了spring提供的@RunWith * 3.告知spring的运行器,spring和ioc的建立时基于xml仍是注解的,而且说明位置@ * @ContextConfiguration: * location:指定xml文件的位置,加上classpath关键字,表示在类路径下 * classes:指定注解类所在的位置 * 当时用spring5.x版本的时候,要求junit的jar包必须是4.12及以上 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = SpringConfiguration.class) //@ContextConfiguration(location= "classpath.bean.xml") public class AccountServiceTest { @Autowired private IAccountService as =null; @Test public void testFindAll() { //3.执行方法 List<Account> accounts = as.findAllAccount(); for (Account account : accounts) { System.out.println(account); } }