Test Readability in a Nutshell

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

7 Tips to Make Your Test Readable

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 getBankAccountService().getBank().getAccounts().get(0) or a accountAt(bank("UberBank")) ?
  • 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!

Advertisements

One thought on “Test Readability in a Nutshell

  1. Pingback: Test readability in a nutshell | Programming | ...

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s