在web项目中,我们有时候需要通过启动tomcat等服务器通过http请求来进行单元测试,其实我们大可不必这么麻烦,
我们可以自己手动的去加载spring中的applicationContext.xml配置文件,方法如下:
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
然后通过 getBean()方法来获取bean,来实现单元测试,大大提高了测试速度.
提高了测试效率.