Question

If I am working on a new class in the C# editor called:

MyCompany.Foo

In the project MyCompany and I wish to create a unit test but in a different assembly it would be nice if I could set up a naming convention and a short cut that would create the test file in a different assembly but in the correct directory with a name similar to the class under test.

For example I would want the above class to generate a test in

  MyCompany.Tests.FooTest

Are there any plugins that do this kind of thing or some variant thereof.

Was it helpful?

Solution

With ReSharper installed, there is an extension called "TestCop" which allows you to generate (or else navigate to) a test class by hitting Ctrl-G Ctrl-T. The naming conventions for your test assembly and test class are configurable. So, for example, you can have your test assembly be the name of your assembly under test plus ".Test" and your test classes be the name of your class under test plus a "Spec" suffix.

I can highly recommend it!

OTHER TIPS

You could use T4 templates in order to generate files in different projects; this uses the T4 Toolbox which is a treasure trove of useful things template related. It is also possible to create templates in Visual studio that will create skeletons for you (there are many template types, i'm just linking to the item template)

Finally you could decide to roll out your own custom tool. I did this tool that outputs (albeit ugly) C# code for testing purposes in order to play with PegJS and Handlebar, feel free to tweak if you're interested. Please note that it doesn't interact with VS at all but it was a funny afternoon project

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top