Import data for visual studio tests

How can I use an external data file in unit tests of Visual Studio? If I try to just include it in a test project and set Copy To Output Directory to true, it still cannot be found.

I have:

[TestMethod]
public void DoMyTest() {
    using (StreamReader rdr = new StreamReader("MyTestData.txt")) {
        blahblah
    }
}

However, the file does not exist, so I get an exception. My test data does not match well with XML or CSV, so using DataSourceAttribute is not a viable option.

+3
source share
1 answer

Add your file as a resource , then call:

string myTestData = Project.Properties.Resources.MyTestData;

, Visual Studio. .

+6

Source: https://habr.com/ru/post/1715089/


All Articles