mardi 29 décembre 2015

Unit test: Could not find data file if it is inside a folder

I am creating data driven unit testing method which uses xml to pass data. I have followed examples which are given in SO and MS website and created a method accordingly.

I have created one xml file inside a directory data in my project. So the path is /data/d.xml. I have set Copy to Output Directory property as Copy always. The problem I am facing here is, the file is being copied to the directory Debug\data\d.xml, but, my unit test method is trying to find it in Debug\d.xml.

How to make my unit test method to find that file in Debug\data\d.xml or How to make my data file moved directly under Debug folder without moving it out of the data directory?
My unit test method is as follows,

    [TestMethod]
    [DeploymentItem("d.xml")]
    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "/data/d.xml", "model", DataAccessMethod.Sequential)]
    public void GetCPCModelTest()
    {
        //some code
        Assert.IsTrue(model != null);
    }

Aucun commentaire:

Enregistrer un commentaire