Sandi Metz (@sandimetz) never lets the audiences down, this time, she brought another great talk on testing. I highly recommend you at least walk through the slides, here is the video if you are blessed.
I learned a lot from the talk that I don’t have to have 100% coverage for the test suite. Here’s some pickups you can take away:
- DO NOT test private method, since they are the most unstable part in the whole object
- DO NOT test out-going query message, it has no side effect to the message receiver
- DO test the out-going command message, ensure you have told the message receiver something it should execute on its part. If you heard about “Tell, don’t ask”, you know that one object should tell another object to do something instead of asking the state of another object and make the decision based on the returned result. Since the out-going command message has side effect to the message receiver, you need to make sure the message is sent out
- DO test the incoming query message, just ensure the return result is expected
- DO test the incoming command message, just ensure the changes is made as expected
That’s all, happy testing. BTW, keep two things in mind for good OO and testing:
- Dependency injection
- Tell, don’t ask