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
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.