A New Way of Testing

03/14/13

A New Way of Testing

A coworker (Brian) pointed me to this groundbreaking series of (short) videos. In them, Mark Seemann does a TDD kata using AutoFixture.

It took me a while to “get” this, and I had to write some code to try it out. But it’s a game-changer.

To get the full benefit of this, you have to be doing dependency injection (DI). Again, Mark Seemann comes to the rescue with his excellent book Dependency Injection in .NET.

When doing DI and TDD (test-driven development), it’s easy to spend a lot of time updating existing tests. You add a dependency, change a constructor, and have to change multiple test cases. There are ways around this (factories, Builder Pattern), but they take some effort.

Also, you can end up with a lot of constants that you don’t care about - test IDs, strings, etc. You need them - your mocks/fakes/doubles return them and your assertions verify the results against them - but you don’t care what they are.

Seemann’s techniques can eliminate most of this. The “arrange” portion of a test case (Arrange-Act-Assert) can shrink drastically.

I have not tried this on a production project yet, but I will be doing so. I want maintainable, easy-to-read unit tests.


Your Host: webmaster@truewill.net
Copyright © 2000-2013 by William Sorensen. All rights reserved.