Posts

Showing posts from April, 2019

Improve Your Unit Testing 12 Ways

Everyone these days seems to understand that having unit tests are an important part of the work of developing software. Yet, people struggle with the practice. Here are 12 ways you can immediately improve your unit tests (and at the bottom, a few ways to go well beyond these 12 rules).  Select assertions to provide clear error messages. Assert.That(x.Equals(y), Is.True) is not it. Try Assert.That(x, Equals(y)) . See the difference in how the test tool explains the failure. If the failures aren't clear, add a text message to the assertion. Go for Maximum Clarity The rule here is "you read the tests to understand the code, you should never have to read the code in order to understand the tests." The tests need to be better documentation than the code or its comments. When this is not true, it's generally because the code isn't doing too many things in a given function. When code is clear and simple, the tests can be also. Watch Out For Side Effects There...