Just digging into some old papers today, I found this old note. I think I did screenshot this long ago from a video by Sandro Mancuso.
1. Class name: The class name is post fixed with Should. This is a pattern that was introduced by Sandro in his lectures. Since tests are probably already in the test package, we don't need to know post fix them with the word test, this class name is more BDD friendly and serves as good documentation.
2. Method name: Is concise and it explains what it does without revealing implementation detail. The words are separated with underscore so that it is easier to read than camel case in a first glance.
3. Assertion written first: By writing the assertion first we reduce the risk of introducing assumptions and over engineer. It helps keeping the code minimal and growing it progressively.
4. Action: Once e have our assertion we will write the action. This maybe seems counter intuitive
but as you will notice, as we are writing the assertion and the action, the code is not compiling, this will force us to code the minimum required to make the test compile.
5. Setup: The last step is to add the setup. With this approach we forced our brain to focus on the behaviour and not on the state. This focus on behaviour is the key for growing the code gradually. Thinking on state first rather than behaviour can lead to assumptions and missed requirements.
This is a very interesting approach which has a lot of benefits. What do you think?
No comments:
Post a Comment