|
|
|
|||
Home Contact MockCreator Competence Projects XPedition Feedback ![]() ![]() ![]()
|
This is the documentation and download page for the ancient version 0.1. This page is just included for historical reasons, please use the most current version. The Mock Creator was developed by Christian Junghans at abstrakt. It is used to generate mockobjects from Java Interfaces. It is developed for VisualAge Version 3 and currently tested under 3.02, 3.53 and 4.0. The current state of the Mock Creator is beta. As it is free software we don't grant any warranty for problems resulting from the use of the Mock Creator. soon here: new versionThe new version includes some enhancements as well as blocks of expectations that may be called in any order. Stay tuned or register to the mailinglist on yahoogroups. It's low traffic, but will receive all announcements. We're currently validating the new generated code (expect blocks of method calls in any order) to see if this implementation makes sense. Additionally the next version of MockCreator will run from VisualAge and Eclipse. To be released end of May 2002. Usage:To create a mockobject simply right-click on an interface in VisualAge and select MockObjectCreator/Create MockObject. The resulting dialog let's you choose a package where to create the mockobject. FunctionalityThe Mock Creator creates mockobjects which implement the choosen interface. The calls to the mockobjects which are expected are defined in the test in the following form. In this case we expect a call to the mockList to the function get() with the parameter 1.
MockList mockList = new MockList(); mockList.expectGet( 1, "Entry 1" ); TestClass testObject = new TestClass( mockList ); testObjekt.methodToBeTested(); mockList.verify(); Each call to an expect-method (in this case expectGet) stores an object-array with methode name and parameters in an ExpectationList (see mockobjects) and the return value (in this case "Entry 1") into a List of return values. Each methodcall that is to be tested on the mockobject checks the method name and parameters with the data set during the expect... methodcalls. The Mock Creator generates two expect-methods for every method in the interface with the following form. (in this case for the method "methodCall"):
public void expectMethodCall
( [all parameters]
[, return value if not void]
);
public void expectMethodCall
( [all parameters]
[, throwable thrown on call
of the method]
);
Using the second version of the expect-call lets you simulate an error condition. In this case the mock-implementation does't return a return value but throws the given exception. Make sure that you pay attention to the interface of the method. If the interface doesn't declare an exception only RuntimeExceptions and Errors may be provided here or you will get a ClassCastException during the test. If the interface declares exceptions you may use these exceptions as the throwable parameter. Installation
Before creating the first mockobject, import the two java classes from the jar file de_abstrakt_mock.jar into VisualAge. It contains the base class for the generated mockobjects and an ExpectationList which was slightly modified to throw an AssertionFailedError if methods where called on the mockobject which where not specified as expected in the tests. The third prerequisite is the import of the package com.mockobjects downloadable from sourceforge. It contains the base class for the modified ExpectationList. Features
Planned features for upcomming releases
Please let us know what features you prefer or if you have other enhancements ideas SupportThe author is available at mockcreator@abstrakt.de. Also there is a mailinglist at http://groups.yahoo.com/group/mockcreator. ProblemsSaving the generated mockobjects takes quite some time, especally with big interfaces. License
The MockCreator is licensed under the
GNU General Public
License (GPL), the imported classes (package
de.abstrakt.mock) are licensed under the
GNU Lesser General
Public License (LGPL). This means, the generated classes are
useful in closed source projects as well. Copyright (C) 2001 abstrakt gmbh This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||