Job Opening for Tester of Web Apps at Moolya >>Could you spot this? This is intentional!

Testing on the Toilet: Only Verify State-Changing Method Calls

This article was adapted from a Google Testing on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office.By Dillon Bly and Andrew TrenkWhich lines can be safely removed from this test?@Test public void addPermissionToDatabase() { new UserAuthorizer(mockUserService, mockPermissionDb).grantPermission(USER, READ_ACCESS); // The test will fail if any of these methods is not called. verify(mockUserService).isUserActive(USER); verify(mockPermissionDb).getPermissions(USER); verify(mockPermissionDb).isValidPermission(READ_ACCESS); verify(mockPermissionDb).addPermission(USER, READ_ACCESS);}The answer is that the calls to verify the non-state-changing methods can be removed.Method calls on another object fall into one of two categories:State-changing: methods that have side...


Share |

Published By: Google Testing Blog - Monday, 25 December, 2017