读取Spring配置文件 main方法里面测试实现功能

  ApplicationContext context = new ClassPathXmlApplicationContext("/webservice-servlet.xml");
  AccountService accountService = (AccountService)context.getBean("accountService");
		Random random = new Random();
		String email = "OoPassAutoTestFengxiang" + random.nextInt() + "@oozic.com";
		String password = String.valueOf(random.nextInt());
		try {
			accountService.register(email, password);
		} catch (OoPassException e) {
			e.printStackTrace();
		}

  

或者使用注解 JUnit 进行白盒测试

@ContextConfiguration(locations = "/webservice-servlet.xml")  

原文地址:https://www.cnblogs.com/shaman/p/2946092.html