O'Reilly logo

The Art of Unit Testing, 2nd Edition by Roy Osherove

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.5. Refactoring to parameterized tests

All the tests you’ve written so far suffer from some maintainability problems. Imagine that now you want to add a parameter to the constructor of the LogAnalyzer class. Now you’d have three noncompiling tests. Going in and fixing 3 tests might not sound so bad, but it could easily be 30 or 100. When it comes to the real world, developers feel they have better things to do than to start chasing the compiler for what they thought should be a simple change. If your tests break your sprint, you might not want to run them or even might want to delete annoying tests.

Let’s refactor them so that you never come across this problem.

NUnit has a cool feature that can help a lot here. It’s called parameterized tests ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required