@Incubating public enum Strictness extends Enum<Strictness>
MockitoJUnit
) or Mockito Session (MockitoSession
).
How strictness influences the behavior of the test?
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.
Enable it via MockitoRule
, MockitoJUnitRunner
or MockitoSession
.
See STRICT_STUBS
for the details.LENIENT
- no added behavior.
The default of Mockito 1.x.
Recommended only if you cannot use STRICT_STUBS
WARN
- cleaner tests but only if you read the console output.
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.
Recommended if you cannot use STRICT_STUBS
.
Introduced originally with Mockito 2 because console warnings was the only compatible way of adding such feature.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 only if you read the console output.
|
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
.
For more information see Strictness
.
@Incubating public static final Strictness WARN
MockitoHint
.
Default Mockito 2.x behavior.
Recommended only if you cannot use STRICT_STUBS
because console output is ignored most of the time.
For more information see Strictness
.
@Incubating public static final Strictness STRICT_STUBS
MockitoJUnit
) or MockitoSession
.
Adds following behavior:
PotentialStubbingProblem
).UnnecessaryStubbingException
).Mockito.verifyNoMoreInteractions(Object...)
you no longer need to explicitly verify stubbed invocations.
They are automatically verified for you.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