MSTest copy file to test run folder

前端 未结 6 1147
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 11:33

I\'ve got a test which requires an XML file to be read in and then parsed. How can I have this file copied into the test run folder each time?

The XML file is set to

6条回答
  •  眼角桃花
    2020-12-04 12:29

    use a DeploymentItem attribute

    using System;
    using System.IO;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using CarMaker;
    
    namespace DeploymentTest
    {
        [TestClass]
        public class UnitTest1
        {
            [TestMethod()]
            [DeploymentItem("testFile1.xml")]
            public void ConstructorTest()
            {
                string file = "testFile1.xml";
                Assert.IsTrue(File.Exists(file), "deployment failed: " + file +
                    " did not get deployed");
            }
        }
    }
    

提交回复
热议问题