I know this is somehow possible, as we have a project that contains MSTest unit tests that are runnable via the VS2010 test runner. We can even add new test methods or classes to the existing projects, and the runner will pick them up and include them in the test run.
The problem comes when I try to add a new unit test project to the solution. If I add a project of the type "test project" to the solution, VS2010 will generate the test metadata and settings files that were not needed for running any of the other tests in the other projects. This is undesirable, for example, for an OSS project. If I simply add a normal "class library" project, and put unit tests in it, the test runner ignores them, and I cannot get it to recognize them at all.
Am I crazy? Is this a fluke? Should it even be possible for VS2010 to run the tests we have, without having a .vsmdi file or a .testsettings file? Or am I missing a setting or configuration that's required in order to make this work for new projects?
You can indeed run tests within VS without having the .vsmdi and .testsettings files (infact, you can just delete them after adding the test project)
So why doesnt it work with a normal class library? the awnser lies inside the .csproj file. This is a regular class library:
And this is a test project:
That last element,
ProjectTypeGuids
is what tells VS that its a project that you can run MSTest tests on. these guids are always the same as far as i know, [at least given the same version of VS] so you should be able to paste that line into any .csproj file and have VS recognize the tests inside.The test settings file can be useful to specify options for deployment (and alot of other things) but most of the options can also be specified at the command line to mstest.exe
The .vsmdi can also be replaced by adding attributes to your test methods. most if not all options available in the
Properties
for a test can be set as attributes as well as in the vsmdi file. i generally prefer the attributes as they are 'closer' to the code.