How to get MSTest to find my test data files?

可紊 提交于 2019-12-03 01:12:16
Daniel Elliott

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"));
}
Matt Salmon

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

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?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!