We are using Testng 6.8.8 + Mockito 1.10.19 and, obviously we can't use MockitoJUnitRunner
, but the validation framework still works!
In this thread I read that it should not be the case. Can someone explain? Is this because we still have @Before
* callbacks and MockitoAnnotations.initMocks(this)
?
My code:
public class MealTransformerTest {
MealTransformer mealTransformer = new MealTransformer();
@Test(expectedExceptions = NotImplementedException.class)
public void shouldThrowException() throws NotImplementedException {
mealTransformer.transform(any(),
any(),
any(),
any());
}
} Nothing fails in this specific test, but when I run the suite, Mockito will tell me about incorrect use of matchers.
I can also do something like:
public class MealTransformerTest {
MealTransformer mealTransformer = new MealTransformer();
//I don't need it in the tests. But I need at least 1 @Mock or @Spy to trigger framework validation
@Mock
private CloneUtils cloneUtils;
@BeforeMethod
void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test(expectedExceptions = NotImplementedException.class)
public void shouldThrowException() throws NotImplementedException {
mealTransformer.transform(any(),
any(),
any(),
any());
}
@Test(expectedExceptions = NotImplementedException.class)
public void shouldThrowException123() throws NotImplementedException {
mealTransformer.transform(any(),
any(),
any(),
any());
}
}
I receive:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaced argument matcher detected here:
....
Don't get me wrong, I really like how it works, but I was surprised to see it without @RunWith(MockitoJUnitRunner.class)
.