My company does not allow to use Mockito.verify in Unit Test. There even is a customized sonar rule about it.
The rule is as below.
The results should be verified by assertions rather than using the verify to do process verification. Because if we verify the process, need more effort to maintain tests after the process is changed,but input and output remain the same. Make sure that every line of code has an impact on the results, and assert the results to prove the logic is correct.
Noncompliant Code Example
verify(graphics2D, times(1)).dispose();// Noncompliant
Compliant Solution
assertThat(((SunGraphics2D) graphics2D).getSurfaceData()).isInstanceOf(NullSurfaceData.class);
For database or middleware operations, assert the data was write successful using the embedded database or middleware.
For restful requests, use wiremock's verify to assert that the mock server received the corresponding request。
WireMock.verify(postRequestedFor(urlEqualTo("http://localhost:8080/query"))
.withHeader("Content-Type", equalTo("application/json"))
.withRequestBody(equalToJson("{" +
"\"testing-library\": \"WireMock\"," +
"\"creator\": \"Tom Akehurst\"," +
"\"website\": \"wiremock.org\"" +
"}")));
My question is, does any other IT company have similar rule to avoid using Mockito.verify in Unit Test? Is it a good rule or evil rule? Thank you very much.