- Choose Parasoft> Preferences> Unit Test Assistant> Mocking to configure mocking options.
- Select the Enabled check box to enable mocking objects during test creation and execution.
- Enable or disable the Use helper methods for mocks option. If enabled, generated tests classes will separate regular test methods from helper methods that prepare objects but do not make assertions.
- Specify the mocking framework that you use.
- If you select PowerMock, specify a list of static methods and constructors to be mocked. Click New to add a new method or pattern. Use qualified method names and wildcards (*) to match patterns. The patterns that end with
<init>will be matched with constructors. For example, the following configuration will mock:
- all constructors in all classes whose names end with "Service",
- all static methods and constructors in all
DAOclasses in all sub-packages of "com.example",
- all methods of the
If the specified pattern matches all methods of a class, UTA will use the
mockStatic()method which mocks all static methods of a class. Otherwise, the
spy()method will be used to mock individual methods that are specified. For details about the
spy()methods, see https://github.com/powermock/powermock/wiki/Mockito#usage.
Only the static methods and constructors specified in the table will be mocked. UTA will automatically add mocks to test templates during test creation, or display recommendations that will help you add mocks after your tests are run (see Creating Mocks).
- Click Apply.