Mock object and EasyMock framework
2011-04-26 17:31
204 查看
You need to familiar with JUnit first.
Link:
http://www.vogella.de/articles/EasyMock/article.html
首先解释什么是Mock object.
Unit testing is defined as testing classes or methods in isolation. Java classes usually depend on other classes. A mock object is a dummy interface or class in which you define the dummy output of a certain method call. These objects can be provided to
the class which should be tested to avoid any dependency to external data. The classical example is a mock object for a data provider. In production a real database is used but for testing a mock object simulates the database and ensures that the test conditions
are always the same.
也就是说,Mock object是为了解决units之间由于耦合而难于被测试的问题。所以mock object是unit test的一部分。
看看另一种类似的解释:
Unit testing is the testing of software units in isolation. However, most units do not work alone, but they collaborate with other units. To test a unit in isolation, we have to simulate the collaborators in the test.
A Mock Object is a test-oriented replacement for a collaborator. It is configured to simulate the object that it replaces in a simple way.
EasyMock provides Mock Objects for interfaces (and objects through the class extension) by generating them on the fly using Java's proxy mechanism. Due to EasyMock's unique style of recording expectations, most refactorings will not affect the Mock Objects.
So EasyMock is a perfect fit for Test-Driven Development.
需要下载。
Link:
http://www.vogella.de/articles/EasyMock/article.html
首先解释什么是Mock object.
Unit testing is defined as testing classes or methods in isolation. Java classes usually depend on other classes. A mock object is a dummy interface or class in which you define the dummy output of a certain method call. These objects can be provided to
the class which should be tested to avoid any dependency to external data. The classical example is a mock object for a data provider. In production a real database is used but for testing a mock object simulates the database and ensures that the test conditions
are always the same.
也就是说,Mock object是为了解决units之间由于耦合而难于被测试的问题。所以mock object是unit test的一部分。
看看另一种类似的解释:
Unit testing is the testing of software units in isolation. However, most units do not work alone, but they collaborate with other units. To test a unit in isolation, we have to simulate the collaborators in the test.
A Mock Object is a test-oriented replacement for a collaborator. It is configured to simulate the object that it replaces in a simple way.
EasyMock provides Mock Objects for interfaces (and objects through the class extension) by generating them on the fly using Java's proxy mechanism. Due to EasyMock's unique style of recording expectations, most refactorings will not affect the Mock Objects.
So EasyMock is a perfect fit for Test-Driven Development.
需要下载。
import org.easymock.EasyMock;
相关文章推荐
- Java开发测试工具用法简略记录——Junit4 And EasyMock
- Rhino Mocks - a popular Mock Object Framework for .NET
- Mock Object Framework
- csharp: NHibernate and Entity Framework (EF) (object-relational mapper)
- Leetcode解题笔记121. Best Time to Buy and Sell Stock [Easy] 动态规划
- About the Monitor object in .NET framework
- 2014-RCNN-Rich feature hierarchies for accurate object detection and semantic segmentation 翻译
- A Fast and Easy to Use AES Library
- About SWFObject generated by Flash Professional, and the HTML tag with clsid
- 第6章gp_toolkit管理架构-Checking Database Object Sizes and Disk Space
- Microsoft Portable Executable and Common Object File Format Specification
- Recognizing and Learning Object Categories --- 连接放送
- EasyIDE ASP Framework - ASP快速开发框架
- ObjectHTML Framework 0.0.9.1 for PHP 发布.欢迎试用
- Google Test and Google Mock
- 在.Net Compact Framework中为ListView添加Context Menu(Tap and hold)
- Python动态执行语句 Executable Object Statement and Built-in Functions
- bat programming is easy and powerful
- Count in String and Object
- mock.patch.object方式写UT