If you are running a unit test that requires an additional item like testing data, xml file, etc, you need some how to copy these files into test run folder. Executing unit test using VS.NET Testing framework is different to other unit test libraries like NUnit which runs the tests using the compiled assemblies in build folder (Debug/Release). Visual Studio creates deployment files under a folder named TestResults within the solution hierarchy. If the TestResults folder does not exist, Visual Studio will creates it. We can deploy dependent test items by different ways. In this post, i will write about the simplest way which is using DeploymentItem attribute. In this example, I want to use file "TestData.xml" in my unit test so I should decorate the test method with DeploymentItem like below:
[TestMethod] [DeploymentItem(@"TestData.xml")] public void Test_Something_Needs_TestData_Xml() { // ... }One more note, to make TestData.xml available for deployment into TestResults folder, this file has to be included in the project and have its "Copy to Output Directory" property set to "Copy Always". Cheers
0 comments:
Post a Comment