Annotation Interface MockitoStrictness


@Documented @Target(TYPE) @Retention(RUNTIME) public @interface MockitoStrictness
Specifies the strictness level for all mocks created in a test class.

The MockStrictness annotation is used to configure the strictness behavior of Mockito mocks within a test class. It allows developers to define how strictly Mockito should enforce the behavior of mocks, such as verifying stubbed methods and detecting unused stubs or unexpected interactions.

This annotation can be applied to a test class to set the default Strictness level for all mocks created by Mockito in that class. The strictness level can be one of the values defined in Strictness, with the default being Strictness.STRICT_STUBS. Strictness Levels:

  • Strictness.STRICT_STUBS Ensures that only stubbed methods are called and reports unused stubs.
  • Strictness.WARN: (default) Warns about potential issues without failing the test.
  • Strictness.LENIENT: Allows unstubbed calls and does not report unused stubs.
See Also:
  • Strictness
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    org.mockito.quality.Strictness
    Specifies the strictness level for all mocks in the test class.
  • Element Details

    • value

      org.mockito.quality.Strictness value
      Specifies the strictness level for all mocks in the test class.
      Returns:
      the Strictness level to apply to mocks, defaults to Strictness.STRICT_STUBS