How To Make Unit Tests a Burden

An entry about tdd Publication date 12. May 2009 16:29

One of the common arguments people have against unit testing, is that it slows them down. And they're right - unit testing will slow you down - if you're doing it wrong.

Brittle Me This

The easiest way to be sure that your tests become a burden, is to write brittle tests. And the easiest way to write brittle tests, is to write tests that make assumptions about the internal implementation of whatever they're testing. For example, by calling private methods from unit tests.

The Fear of Refactoring

One of the huge advantages of having a set of unit tests, is the safety net they provide which allows you to refactor code without the fear of breaking stuff. If however by refactoring your code you break the tests and thus also have to refactor them all the time, not only are you compromising the value of the tests, you're also introducing a lot of extra work for yourself.

The Value of Resilience

Whether you're writing state or behavior based tests, try to keep knowledge about internal implementations of the thing you're testing out of the test, and you'll find that your tests become much more resilient to change, and thus much more valuable.

Currently rated 4.0 by 2 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Powered by BlogEngine.NET 1.4.5.0

Welcome!

My name is Fredrik Kalseth, and this is my blog - thanks for visiting! I am fortunate enough to work with what I love for a living, and this blog is essentially the biproduct of that.

I work as a senior consultant for Capgemini, and am also an active participant in the Norwegian .NET community, as an avid attendee but also as a speaker (most recently at NNUG and MSDN Live).

As a developer, I have a wide circle of interest. My primary passion is for agile, test-driven development, with focus on best practices and clean code. That said, I also love to work on the frontend, especially with web development.

On Twitter? My handle is fkalseth. On LinkedIn? I`m there too.


Disclaimer

This is a personal blog; any opinions expressed here are my own and do not necessarily reflect those of my employer. All content herein is my own original creation, and as such is protected by copyright law. Unless otherwise stated, all source code posted on this blog is freely usable under the Microsoft Permissive License.

What Readers Talk About

Comment RSS