Spring框架在测试应用方面有什么好处?
我们已经听说过很多关于 Spring 的好处,比如它提供了松散耦合、依赖注入、控制反转等,但从测试的角度来看,我有几个问题。
- Spring 框架在测试应用程序方面有哪些优势?
- 为什么使用 Spring 开发的应用程序被认为是可测试的,而不是其他 Web 应用程序?
请提供一些有用的例子,这样解释起来会更容易理解。我是 Spring 的新手,想从应用程序开发人员的角度了解 Spring Framework
提供的确切好处?
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.
- What are the advantages of Spring Framework in terms of testing an application?
- Why Application developed using Spring as considered my testable as opposed to other Web Application?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
面向依赖注入的应用程序通常更容易测试,因为资源很容易被面向测试的资源替换。考虑一个使用数据访问对象的服务对象;在生产中,您将注入一个与后端数据存储对话的 DAO。但对于每个测试,您可以创建一个返回特定已知数据的 DAO;这使您可以专注于正在测试的对象。
Spring 是 Java 的众多依赖注入框架之一,尽管它是最流行的;任何 DI 框架都会给你带来这种好处。
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; in production, you'd inject a DAO that talked to a backend data store. But for each test you could create a DAO that returned specific, known data; this allows you to focus on the object being tested.
Spring is one of many dependency injection frameworks for Java, albeit the most popular; any DI framework is going to give you this kind of benefit.