Mocking Annotations
Mocking annotations allow fine grained control over what mocking should be preferred when testing.
Using @InTestsMock
@InTestsMock
Perhaps you have a method that Diffblue Cover would ordinarily test using an Integer
but you'd prefer to see it tested using Mockito.mock(..)
. In this case you could annotate the method (or class, or package) to recommend mocking Number
:
Conversely, if Diffblue Cover normally does mock a particular class, and you have a particular location where it shouldn't be then you can forbid it:
Note that using @InTestsMock
has the same effect as, and can be overridden by, Cover CLI command line options:
Using @InTestsMockConstruction
@InTestsMockConstruction
Perhaps you have a method that Diffblue Cover is unable to test, and you think it could make more progress using Mockito.mockConstruction(Random.class)
. In this case you could annotate the method (or class, or package) to recommend mocking construction of Random
:
Note that using @InTestsMockConstruction
has the same effect as, and can be overridden by, Cover CLI command line option:
Using @InTestsMockStatic
@InTestsMockStatic
Perhaps you have a method that Diffblue Cover is unable to test, and you think it could make more progress using Mockito.mockStatic(UUID.class)
. In this case you could annotate the method (or class, or package) to recommend mocking static methods of UUID
:
Note that using @InTestsMockStatic
has the same effect as, and can be overridden by, Cover CLI command line option:
Last updated