I can\'t seem to grasp how MSTest deployment items are supposed to be configured. I have been able to get them working properly by modifying the project\'s test settings fil
I thought I'd share a way I ran into problems with MSTest and deployment items. If you Debug/Run your test a 2nd time or more from the "Test Results" window, it uses the settings from a previous run. However, if you Debug/Run the same test from the "Test View" window, it uses the latest settings. I lost an hour to trying to figure out why changes to Local.testsettings weren't being used when I kept starting Debug on the same test from the "Test Results" window.
This is the Test Results window (do not [re]start tests from here after making changes to Local.testsettings):
And this is the Test View window (DO start tests from here after making changes to Local.testsettings):
I hope this saves someone a headache in the future.
If you need separate deployment item in individual test cases then please go ahead and use [DeploymentItem("string file path")]
attribute in each test cases.
In Visual Studio 2012 the output directory is the working directory which means that the DeploymentItem attribute isn't needed for the general case (where you don't have specific per-test or per-class deployment items). This means that if you don't need to use the DeploymentItem attribute if there is a set of files that you want all your tests to use or you are not too pernickety about each TestClass/TestMethod having separate deployment dependencies.
You can simply click Project | Show All Files and include the subfolders and files in Visual Studio with the 'Copy always' or 'Copy if newer' attribute to your project and the files will be copied to your output directory with hierarchy intact.
The same applies when running vstest.console.exe from the command line. See here for the details.
Update
There are cases where the default directory will not be the output directory. Specifically when you choose Run All Tests
the default path would be under TestResults\Deploy_...
The same applies when using a runsettings
file or tests use DeploymentItems
The output directory will be the default directory when you are not using DeploymentItems and: -
Looks like this works by default in VS.NET 2012
In VS 2012, All you need is to make the log4net.properties (or whatever config file for log4net ) file Copy if newer. ( right click log4net.properties file to bring up the properties and configure it )
For my case, I add the DeploymentItem attribute, it can't take effect immediately. I have to close and re-open the solution, then the configured DeploymentItem attributes will take effect.