I have been working on a new codebase and it was really hard to understand their code. I have come to understand the business rules verbally quite well, but I haven’t been able to find these rules matching into the code.
Then I thought that maybe it would be better if I got to understand the unit tests. After all, each business rule should be clear by scanning each test case but that was even worse!!.
I didn’t know what each scenario was about, what kind of data should be in place or even what business rule the scenario was verifying. I remembered an article I read a couple of weeks ago about code testability
and instantly proceeded to redo these tests all over again, you know, for my benefit and that of future generations.
To this article I would have to add a couple more tips, which would add a lot of value to the readability of the code:
- Define a business DSL for your tests. I mean, is it better to understand a
- Reduce test documentation. Admit it, most programmers don’t maintain Javadocs, but they do maintain code! So get your hands on your codebase, reduce documentation to a minimum and try to make your tests as readable as possible. This applies to regular code too.
Do you have any extra tips on test readability? Please let me know!