您的位置:首页 > 移动开发 > Objective-C

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.

需要下载。

import org.easymock.EasyMock;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: