Little things matter.

Cover your code in unit tests.

As you refactor your code into smaller and smaller pieces, it becomes easier to cover these shrunken methods with unit tests. The less logic that resides in a method, the less there is to test. This makes it simpler to provide full coverage of the methods that make up a class.

Unit tests are simple things. The only test the logic in the method; outside dependencies are typically mocked out. The methods called within the logic are tested elsewhere. Because they are simple, it is easy for a new person to understand the code and what the tests are trying to do.

One should aim for 100% coverage, where reasonable. Be sure to use a variety of examples including both common and edge cases, so you can test the various branches in the code.

Unit tests are not sufficient to prove the application works; after all, one can assemble the wrong application using perfectly fine building blocks. Integration and behavior tests are still needed. Still, unit tests are highly valuable and simple to add, so should be required part of the application.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: