简体   繁体   English

Spring框架在测试应用方面有什么好处?

[英]What are the benefits of Spring Framework in Terms of Testing Application?

We have heard a lot about Benefits of Spring like it offers loose coupling, dependency injection, inversion of control etc but from testing point of view, I have couple of question.我们听说过很多关于 Spring 的好处的信息,比如它提供loose coupling, dependency injection, inversion of control etc ,但从testing的角度来看,我有几个问题。

  • What are the advantages of Spring Framework in terms of testing an application? Spring 框架在测试应用程序方面有哪些优势?
  • Why Application developed using Spring as considered my testable as opposed to other Web Application?为什么使用 Spring 开发的应用程序被认为是我的可测试应用程序,而不是其他 Web 应用程序?

Please provide some useful examples as then it would be much more easier to understand explanation.请提供一些有用的示例,因为这样会更容易理解解释。 I am new to Spring as such and want to understand precise benefits offered by Spring Framework from Application Developer point of view?我是 Spring 的新手,想从应用程序开发人员的角度了解Spring Framework提供的确切好处?

An application geared towards dependency injection is typically more testable because resources are easily replaced with test-oriented resources.面向依赖注入的应用程序通常更易于测试,因为资源很容易被面向测试的资源替换。 Consider a service object that uses a data access object;考虑使用数据访问 object 的服务 object; in production, you'd inject a DAO that talked to a backend data store.在生产中,您将注入一个与后端数据存储通信的 DAO。 But for each test you could create a DAO that returned specific, known data;但是对于每个测试,您都可以创建一个返回特定已知数据的 DAO; this allows you to focus on the object being tested.这使您可以专注于正在测试的 object。

Spring is one of many dependency injection frameworks for Java, albeit the most popular; Spring 是 Java 的众多依赖注入框架之一,尽管它是最流行的; any DI framework is going to give you this kind of benefit.任何 DI 框架都会为您带来这种好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM