Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relative path root of DeploymentItemAttribute?

Using MSTest, what is the relative path root of the DeploymentItemAttribute.

like image 847
Anthony Mastrean Avatar asked Nov 30 '09 21:11

Anthony Mastrean


2 Answers

Per the MSDN page...

Relative paths are relative to the RelativePathRoot setting found in the .testrunconfig file.

That setting is, by default, the Solution directory. So, if you have this project structure

SecretProject\
    ComponentA\
    ComponentA.Test\
        Resources\
            required.xml
        ComponentA.Test.csproj
        Tests.cs
    SecretProject.sln

And you want to deploy required.xml, you're going to create a DeploymentItemAttribute like this

[TestClass]
public class Tests
{
    [TestMethod]
    [DeploymentItem("ComponentA.Test\Resources\required.xml")]
    public void Test() 
    {

    }
}

It seems the file properties need to be set to 'Content' and 'Copy always' or 'Copy if newer'. There are advanced examples on this MSDN page.

like image 90
Anthony Mastrean Avatar answered Oct 20 '22 18:10

Anthony Mastrean


To assume that the RelativePathRoot default is the dir where your solution resides was not correct in my case, nor was RelativePathRoot defined within my .testrunconfig file. I found the RelativePathRoot default to be the /bin/debug dir for the solution.

Walking back from that point, then walking up to my file that I was attempting to deploy for the unit test worked fine.

like image 1
kodjeff1 Avatar answered Oct 20 '22 18:10

kodjeff1