2

In visual studio 2008 Professional, when I create a unit test for a method (using the native vs studio framework and wizard), the generated test file stub is saved in the root directory of the test project.

When I later move the test file to a sub-directory, I cannot use the wizard to create more test stubs for other methods of the same class ( it will create a new empty file in the root and then silently fail )

How can I change this so the test project uses the same folder structure as my main project; so if a class is e.g. in project-root\model\xyz.cs, the corresponding test class is automatically generated in testproject-root\model\xyzTest.cs ?


edit:

Add the moment, this seems to be an unsolved bug with visual studio. Besides the workaround described in the answer below, another possibility is to simply rename the autogenerated test classes after moving the respective test class files. Then Visual Studio will at least not silently fail but recreate the old test class file in the root folder when generating another test method, and that test method can then be copy-pasted into the correct file

HugoRune
  • 13,157
  • 7
  • 69
  • 144

2 Answers2

1

I just confirmed your problem, When adding more tests for the file I moved i just got the first 2 lines of the file generated.

I'm guessing the wizard just doesn't know how to look in subfolders to know what file to add it to, but errors when trying to generate a second class of the same name. (I'd guess if you rename any of the test files but leave them in the root it would also have this problem, but I didn't test this idea)

So I don't think there is anyway around it if you want to continue to use the wizard. You should be able to move it to the root, use the wizard, and move it back right. That's the best option I can think of.

I'm thinking the test abilities were greatly improved in VS2010, I have not used that but maybe the fixed it for that version...

This answer offers a solution, using a 3rd party code template.

Community
  • 1
  • 1
Thymine
  • 8,775
  • 2
  • 35
  • 47
0

The only thing you need to do when moving or renaming the folder is to include the dll, exe, or manifest properly from your main project.

It sounds like you want it to not only be in a separate folder but also in a separate project?

After you have your folders arranged how you want them, right click references for your test project and click "Add Reference". Click the "Browse Tab" and then find your main project, go into its bin/Debug folder and select the appropriate dll or exe.

This of course assumes you can first compile your main project. To only compile your source project, right click it in your solution explorer, click "Build" or "Debug/Start New Instance".

That should hopefully work. I hope :p.

Parris
  • 17,833
  • 17
  • 90
  • 133