单体测试mock对象工具简介

(1)什么是mock对象?

from: http://www.easymock.org/

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. In contrast to a stub, a Mock Object also verifies whether it is used as expected. Tim Mackinnon, Steve Freeman and Philip Craig pioneered the concept of Mock Objects, and coined the term. They presented it at the XP2000 conference in their paper Endo Testing: Unit Testing with Mock Objects. A reworked version of the paper is published in the book Extreme Programming Examined (Addison-Wesley).

(2)EasyMock has been the first dynamic Mock Object generator, relieving users of hand-writing Mock Objects, or generating code for them. It was presented for the first time at OOPSLA 2001.

EasyMock为Mock Objects提供接口并在JUnit测试中利用Java的proxy设计模式生成它们的实例。EasyMock最适合于测试驱动开发。 (from: http://www.open-open.com/open64643.htm)

(3)about mockmaker,from http://mockmaker.sourceforge.net/, we see that,

MockMaker is a program for creating source code for mock object classes. Given an interface, it writes the source code for a mock object class that implements the interface and allows instances of that class to have expectations set about how many times a method is called, what parameters each method is called with, and to pre-set return values for methods. In many cases (possibly most cases), the classes produced by MockMaker are exactly what you want a mock class to do.

(4)about mockDoclet,MockDoclet is an active code generation tool for automatically generating mock objects implementation classes from existing classes or interfaces in Java.(from:http://joe.truemesh.com/mockdoclet/)

(5)about jmock,jMock is a library for testing Java code using mock objects1.(from:http://www.jmock.org/)

(6)What is the MockCreator? MockCreator, first coded at German company Abstrakt Gmbh, and enhanced by me, Vladimir Dyuzhev, is the generator of mocks. Given an interface or a class, it generates source of mock class for it. however, this project has been cancelled due to lack of time, what a pity.(see it at http://mockcreator.sourceforge.net/).

(7)About Mock Objects, a technique for improving the design of code within Test-Driven Development, see it at http://www.mockobjects.com/

(8)mock入门可以参考:Mock Object工具横向比较(http://java.ccidnet.com/art/3737/20051017/472031_1.html)

你可能感兴趣的:(object,测试,工具,generator,interface,testing)