@Incubating public enum Strictness extends Enum<Strictness>
Strictness
drives cleaner tests and better productivity.
The easiest way to leverage enhanced Strictness
is using
Mockito's JUnit support (MockitoRule
or MockitoJUnitRunner
).
If you cannot use JUnit support MockitoSession
is the way to go.
How strictness level influences the behavior of the test (mocking session)?
LENIENT
- no added behavior.
The default of Mockito 1.x.
Recommended only if you cannot use STRICT_STUBS
nor WARN
.WARN
- helps keeping tests clean and improves debuggability.
Reports console warnings about unused stubs
and stubbing argument mismatch (see MockitoHint
).
The default behavior of Mockito 2.x when JUnitRule
or MockitoJUnitRunner
are used.STRICT_STUBS
.
STRICT_STUBS
- ensures clean tests, reduces test code duplication, improves debuggability.
Best combination of flexibility and productivity. Highly recommended.
Planned as default for Mockito v3.
See STRICT_STUBS
for the details.
Enum Constant and Description |
---|
LENIENT
No extra strictness.
|
STRICT_STUBS
Ensures clean tests, reduces test code duplication, improves debuggability.
|
WARN
Helps keeping tests clean and improves debuggability.
|
Modifier and Type | Method and Description |
---|---|
static Strictness |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static Strictness[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
@Incubating public static final Strictness LENIENT
STRICT_STUBS
nor WARN
.
For more information see Strictness
.
@Incubating public static final Strictness WARN
MockitoHint
.
Default Mockito 2.x behavior.
Recommended if you cannot use STRICT_STUBS
.
For more information see Strictness
.
@Incubating public static final Strictness STRICT_STUBS
Adds following behavior:
PotentialStubbingProblem
).UnnecessaryStubbingException
).Mockito.verifyNoMoreInteractions(Object...)
you no longer need to explicitly verify stubbed invocations.
They are automatically verified for you. However if you have more invocations,
the test won't fail since it won't check that there are no more interactions on that stub.Strictness
.public static Strictness[] values()
for (Strictness c : Strictness.values()) System.out.println(c);
public static Strictness valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null