COVIEW for eclipse
Create JUnit tests and mocks, measure coverage

Details | Download

purchase CoView and Comet
COMET for ant
Measure coverage and metrics in a CI environment

Details | Download

purchase CoView and Comet

CoView Mock Object Creator

Unit testing is simple, right? It's simple if you are passing in integers and doing some basic calculations. It gets much more complicated as you start to deal with real world code. It gets so complicated that you often spend more time creating your mock objects than writing unit tests. The more complicated the class, the more mock objects you need.

So how can CoView help? CoView not only creates the JUnit tests for you, it also creates the mock objects as well. In fact, it can easily create all the mock objects on a particular path.

CoView offers two ways to create mocks using JMockit. Either as you create the CoView JUnit test case or simply add them to an existing test case.

As You Create A New CoView JUnit Test Case

As part of the CoView wizard that creates JUnit tests, you have the option to create mocks for the following:

  • argument objects passed directly to the method under test or fields (which are used in the method under test) which can be set by public methods of the class under test
  • public instance (i.e. non-static) methods of the class under test (of course other than the method under test) which the method under test invokes
  • private/protected fields of the class under test containing some objects that the method under test uses directly, without calling public getters
  • private/protected methods of the class under test which return some objects the the method under test uses. The method under test invokes them directly without help of public methods.
  • objects instantiated within the method under test by the "new" operator
  • various static invocations from the method under test
  • methods of JDK classes

creating mocks with CoView and JMockit

Add Mocks To Existing JUnit Tests

CoView lets you easily identify mockable invocations by using short-cut keys like ctrl-1. Using various decorators and colors, CoView identify invocations that have already been mocked in other tests or invocations that have no associated mocks.

Either way, a wizard is displayed that let's you decide to create a new mock or use an existing one.

creating mocks with CoView and JMockit