org.mockito.quality
public interface MockitoHint
How to take advantage of the hints? Use one of the JUnit integrations:
Currently, the feature is available with JUnit Rule and JUnit Runner only because they provide necessary hooks (the 'before' and 'after' test events).
UnnecessaryStubbingException
.
Example:
Let's say the test fails on assertion. Let's say the underlying reason is a stubbed method that was called with different arguments:
//test:
Dictionary dictionary = new Dictionary(translator);
when(translator.translate("Mockito")).thenReturn("cool framework");
String translated = dictionary.search("Mockito");
assertEquals("cool framework", translated);
//code:
public String search(String word) {
...
return translator.translate("oups");
On standard output you'll see a hint with clickable links to both locations:
a) stubbing declaration and b) the method call on a stub with mismatched argument.
Note that it is just a warning, not an assertion. The test fails on assertion because it is the assertion's duty to document what the test stands for and what behavior it proves. Hints just makes it quicker to figure out if the test fails for the right reason.
Feedback very welcome at issue 384.