Unit Testing Pro Tip: Verify that your tests make assertions about the method under test and nothing else

Nothing else. Don’t make assertions about the code you wrote in the test. Don’t make assertions about other methods in other classes. Isolate the method you’re testing using mocks or stubs and only test the method you’re testing. Your tests will be more clear and easier to debug.

To do this, start by looking at each line in the method you’re testing. Make an assertion about that line and nothing else. Repeat until you’ve made assertions about each line. Don’t add any other assertions.

Oh and if you want to ensure you always do this, just practice test-driven development. Write the tests first, then make them pass. It’s a lot easier to mess up tests if you write them after the production code.

Questions? I’d love to help. josh@roadfiresoftware.com