I have a simple question about best practices in unit test verifications. Given this example:
@Test
public void methodUnderTest() {
when(mockedDependency.someMethod()).thenReturn(someValue);
int actual = classUnderTest.methodUnderTest();
assertEquals(5, actual);
verify(mockedDependency).someMethod();//should I do this?
}
As you can see I'm checking that my mock is being used. Should I do this?
With this verification if I change the implementation of the method (removing the usage of that dependency) my test is gonna fail and I'm forced to remove when and verify.
Without this verification if I change the implementation of the method my test is gonna pass but I will never know that in that test I'm mocking something that is not needed and when I will see that test again I will think that in my implementation I need that dependency.
Thanks in advance.
classUnderTestto themockedDependency? Does theactualresult depend onsomeValueyou use to mock?