Specify a file or directory that should be deployed along with the assemblies before running a test. Attach this attribute to a test class or test method. You can use multiple instances. This attribute is not inherited.
Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework (in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)
Thetype exposes the following members.
|Equals||Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)|
|GetHashCode||Returns the hash code for this instance. (Inherited from Attribute.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|IsDefaultAttribute||When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)|
|Match||When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|_Attribute.GetIDsOfNames||Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)|
|_Attribute.GetTypeInfo||Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)|
|_Attribute.GetTypeInfoCount||Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)|
|_Attribute.Invoke||Provides access to properties and methods exposed by an object. (Inherited from Attribute.)|
Visual Studio 2012 runs tests either in the folder in which you have built them or in a separate deployment folder that is unique to the test run. If a deployment folder is used, the test engine creates a deployment folder and copies into it the assemblies containing the test code, the application, and any assemblies they reference.
But some tests require additional files, such as test data, configuration files, databases, or explicitly loaded assemblies. To make these files available during the test, you have to specify that they should be copied along with the test assemblies. Here’s the best way to do this:
Copy the files to the build target directory as part of the build process.
If they are specific to one test project, include them as content files in the Visual Studio test project. Select them in Solution Explorer and set the Copy to Output property to Copy if Newer.
Otherwise, define a post-build task to copy the files into the build output directory. For example:
xcopy /Y /S "$(SolutionDir)SharedFiles\*" "$(TargetDir)"
Open the project properties of your test project. In a C# project, open the Build Events page. In a Visual Basic project, open the Compile page and choose Build Events. Add the copy command to the Post-build event field.
Use on test methods or test classes to specify the files and folders that should be copied from the build output directory to the deployment directory.
Consider running your unit tests directly in the build output directory, so that testing runs more rapidly. This is especially useful on the build server after you have checked in your tests. To do this, add a .runsettings file to your solution, include <DeploymentEnabled>False</DeploymentEnabled>, and select the file in the Test, Test Settings menu. The same effect occurs in any test run in which DeploymentItemAttribute is not used at all.
However, you might prefer not to do this if you want to be able to inspect the data files after a failed run.
You cannot avoid using a deployment folder if you are using a .testsettings file, which is required for web and load tests, coded UI tests, and any test in which you deploy an application to remote machines.
In a test run, all the items in the tests that are to be run are deployed before any test is started.
For more information, see How to: Deploy Files for Tests.
has two parameters:
Source item path is relative to the build output folder. It can be a file or folder. To avoid dependency on your project structure, move the item into your build output directory as part of the build process. Use the deployment item attribute to deploy it from there.
(Optional) Target directory path must be a folder, and it is relative to the deployment directory. If the folder does not exist, it will be created. The default value is the deployment directory.
You cannot change the file name by using DeploymentItem.
The following examples demonstrate usage of the :
For more information about how to use attributes, see Extending Metadata Using Attributes.
The following test reads files named "test*.xml". To make the files available to the test and to the application under test, they are identified by using the . The test method will verify that the files exist under the deployment directory, before going on to test the application.