Moving MSTEST classes into their own folders break

2019-04-11 06:25发布

问题:

I like to organize my unit test classes into functional areas using folders, much like the process I use to organize my application classes.

However, the "Create Unit Tests" option in the right-click menu for a method breaks if the original target test class is moved to a new location, presumably because the code generator is trying to create a new class of the same name in the root of the Unit Tests project.

I can fix the problem temporarily by moving the original test class into the root of the Unit Tests project, prior to executing "Create Unit Tests...", and then move it back into its original folder when the code generation is complete, but this is clumsy.

Is there a better way to manage this?

回答1:

This is by design. I use the same strategy of having folders to split up my tests, and when I add a new unit test, VS will create the class in the root folder.

So, I ended up using a code template (in Resharper) that I use to create a new unit test class in a folder. I suggest you do the same - if you don't use Resharper then have a Visual Studio code snippet like the ones found here.