JUnit: Misuse Of any() Matchers

For writing unit tests in JUnit, Mockito provides argument matchers that you can use to mock the arguments in a given() or when() statement. Among the matchers provided, the any() matcher lets you pass any argument to the method, ensuring that the test cases passes with any input. When any() matcher is used extensively, out of laziness of specifying the parameters, there are high chances that the test case is not really testing anything or it passes even with a wrong input....

July 23, 2021 · 2 min · Me