A new year is upon us, and I bet your new year’s resolution is to start unit testing. What instruments do you need in your belt?
- A testing framework (gasp!). I know, shocking, but you need one, and there’s so many out there, you don’t need to build your own. Test frameworks allow you to run your test and give you asserting APIs to pass or fail your tests. There are so many to choose from: In the .Net space there’s NUnit, MSTest, xUnit, MbUnit, and other small ones. In C++ there’s cppUnit, GoogleTest and many others and you’ll get many choices in any language and technology, just look for something with the word UNIT in it.
- A mocking framework. This may look like an advanced option, but trust me – you want it from the beginning, especially if you’re going to test legacy code (and who doesn’t have it?). There are open source and commercial options out there, but if you want the power tools for professionals, get Isolator.NET and Isolator++.
- An automated build server (or continuous integration server). Running your tests on your computer is cool, but let’s face it – unit testing is a team sport. You want a separate computer that connects to your source control system (you do have one, right?), gets the latest version, compiles your code, runs all tests and gives you a test result report. Which you should look at. There’s a bunch of them out there, free and commercial, from NAnt to Microsoft TFS. Choose the one that’s easiest for you to configure. It’s not a hassle to start, and really proves indispensible once you start using it.
- Optional (but if you’re serious about testing, and you should be): a coverage reporting tool. Those tools can be quite complex (the commercial ones give you lots of reporting options), but all you need to begin with, is a basic report that tells you that you’re adding more and more coverage with your tests. You can start without it, but there’s a nice fuzzy feeling looking at a rising graph of coverage percentage. And you can show this to managers, because we all know managers like reports, right?
That’s what you need, so go write some tests. If you already do, write us a comment: What’s in your tool belt?