Spring框架是无侵入性的,所以你的代码可以完全是POJO(plain old java object),直接使用Junit就可以完成大部分的单元测试.但是在集成测试方面就比较吃力了.单元测试层面你可以mock一些依赖对象,但是集成测试时需要真实的依赖对象,而这些对象都是在Spring容器的控制之下.那么如何在引入了Spring的情况下进行集成测试那?别着急,Spring框架早为我们想到了这点,本身提供了集成测试的功能. 就拿上一次那个简单的例子来做实验吧. 首先引入对junit以及sprin…