How to get MSTest to find my test data files?

后端 未结 3 1634
别跟我提以往
别跟我提以往 2021-02-05 03:00

I have a few tests that need to be fed with external data from excel files. The files are included in the test project, and in Visual Studio, I have edited the test settings fil

相关标签:
3条回答
  • 2021-02-05 03:40

    This post answers this question: MSTest copy file to test run folder

    0 讨论(0)
  • 2021-02-05 03:53

    The accepted answer is technically correct. However, from my experience, I find that the embedding files as resources requires an additional step of remembering to set the property "Embedded Resource". This becomes a challenge when you have a large number of data files. Also, with increasing number of data files, the size of the unit test assembly keeps growing . In my case, I had over 500MB of test data files and packing all them into the assembly was not a good idea.

    What is the alternative?

    Let the data files remain as they are. Do not use DeploymentItemAttribute, do not use embedded resources. Please refer my proposed solution How do I make a data file available to unit tests?

    0 讨论(0)
  • 2021-02-05 03:56

    I get round this by adding my data files (in my case usually XML) as embedded resources and I extract them from the test assembly.

    [TestInitialize]
    public void InitializeTests()
    {
        var asm = Assembly.GetExecutingAssembly();
        this.doc = new XmlDocument();
        this.doc.Load(asm.GetManifestResourceStream("TestAssembly.File.xml"));
    }
    
    0 讨论(0)
提交回复
热议问题