Package org.mockito

Annotation Type DoNotMock


@Target(TYPE) @Retention(RUNTIME) @Documented public @interface DoNotMock
Annotation representing a type that should not be mocked.

When marking a type @DoNotMock, you should always point to alternative testing solutions such as standard fakes or other testing utilities. Mockito enforces @DoNotMock with the DoNotMockEnforcer. If you want to use a custom @DoNotMock annotation, the DoNotMockEnforcer will match on annotations with a type ending in "org.mockito.DoNotMock". You can thus place your custom annotation in com.my.package.org.mockito.DoNotMock and Mockito will enforce that types annotated by @com.my.package.org.mockito.DoNotMock can not be mocked.


 @DoNotMock(reason = "Use a real instance instead")
 class DoNotMockMe {}
 
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The reason why the annotated type should not be mocked.
  • Element Details

    • reason

      String reason
      The reason why the annotated type should not be mocked.

      This should suggest alternative APIs to use for testing objects of this type.

      Default:
      "Create a real instance instead."