As part of the series on plug-ins available for Visual Studio 2013, I’ll write a little about the Unit Test Generator.
In VS2010, we had the ability to right click on a class or method, and make the IDE scaffold a unit test. That disappeared in VS2012, but the unit test generator extension adds the feature back in.
You can download the VSIX installer from here.
Once you’ve installed it and rebooted VS, it’s simple to scaffold unit tests for your class. Just right click on the class name, and select “Generate Unit Tests” from the context menu (see below).
A dialog window will appear where you can choose how your unit test project is scaffolded out.
I prefer to:
- Add my unit tests to a separate project to the class implementation;
- Use NUnit (actually I’d prefer Xunit given that I now know that’s what Microsoft are using to unit test the .net core, but the xUnit test-runner doesn’t play nicely with dotCover 2.6 so until I upgrade, I’m sticking with NUnit); [Edit: I’ve blogged about this here]
- Create a test class with the same name as my implementation, but suffixed with “Test”;
- Create default test methods with the same name as the method under test, but again suffixed with “Test”;
But the tool lets you customize how you want to see your test appear.
Obviously it’s really easy/trivial for a developer to do all of this by hand – it’s just a time saver. But it’s a good one – if you create unit tests (and you really should), this extension will save you the grind of creating a test project, downloading your preferred flavor of unit test framework from nuget, creating a test class, stubbing out tests for your public methods.
You can read the Visual Studio ALM Rangers blog entry announcing this extension here.
You can watch the Channel 9 introduction to using the extension here.