MSTest, VS 2010 and reflected dlls
I am working on an automation framework based on C#.NET and VS 2010. One of the more annoying attributes of MSTest is that it doesn't copy over all the files from \bin\debug to the 'out' directory where it runs the tests.
Today I found out about 2 ways I can make working in MSTest more palatable (I'm an NUnit guy by nature).
References
- Create Test Settings to Run Automated Tests from Visual Studio [msdn.microsoft.com]
- MSTest DeploymentItem doesn't copy files to output dir [stackoverflow.com]
Interesting Item #1: DeploymentItem
When you setup a test solution and don't link all the DLLs to your test project, some of your dlls will be left behind. Apparently you can use a [DeploymentItem(@"")] attribute to specify additional items you want copied along with the test DLL:
namespace Automation.Tests.REST { [TestClass] public class RestCliTests { [TestMethod] [DeploymentItem(@"TestProjectName\SharedDlls\SharedDll1.dll")] [DeploymentItem(@"TestProjectName\SharedDlls\SharedDll1.pdb")] [DeploymentItem(@"TestProjectName\SharedDlls\SharedDll2.dll")] [DeploymentItem(@"TestProjectName\SharedDlls\SharedDll2.pdb")] public void WindowsBoxCliTest() { // Test Code Here }
Interesting Item #2: Run MSTests from the local build directory instead of the 'OUT' folder
This is the more interesting item I want to note down. You can adjust the .testsettings for your test solution and make it so that the tests run from the local bin\(debug|release) folder. In many ways this makes things much more straight forward than deploying to the out directory. The only limitation that I can see is that if you want to keep copies of your old test environments around, deploying to out is the better approach (since it caches the DLLs and files used in that specific test).
To make the change to running tests locally:
- Open your Test Solution
- Expand the Solution Items folder
- Open your <ProjectName>.testsettings file
- Click on the Deployment section
- Uncheck the Enable Deployment checkbox
- Save the settimngs
Here's a screencap that shows what it looks like in VS2010: