I’m not overly fond of the MS Test framework for unit testing, but it’s what we’re stuck with I mean using so I’m pressing on with it. The test manager makes it difficult to organize and run tests, and I greatly dislike how slow it is.
Today I’ve found some other friction in MS Test that’s even more of a PITA: External items aren’t copied to the test output directory unless you jump through several other hoops.
My current test environment uses a number of XML and HTML files as input and reference data. I keep those files in a folder separate from my test classes since they’re used by a number of different test projects. I use Add -> Existing Items and add those items as links to the various projects — and then set “Copy to Output Directory” to “Copy if newer” to ensure things get dragged over as appropriate.
This works just fine using TestDriven.NET to run tests; however, MS Test adds some additional complexity in order to get such items over to the test folder. Instead of relying on the “Copy to Output Directory” property, you’ll need to specifically call out the items via one of two methods: the DeploymentItem attribute or by specifically adding those items in to your test run configuration.
The DeploymentItem attribute looks like this:
Unfortunately it didn’t work when added to a ClassInitialize setup method, so I turned to the test run configuration’s Deployment tab where you can add files or directories to carry over to the test run output folder.
Irritating, overly complex, and an additional layer of brittleness should I need to change anything. -1 (again) for MS Test.