I'm writing a unit test that reads data from a json file. Currently the directories are like this:
Unit test: ..\Source\Repos\ReposName\Project.Tests\MyUnitTest.cs
Test data: ..\Source\Repos\ReposName\Project.Tests\testData\testData.json
Now in my unit test, I'm trying to read the testData.json into a string that can be deserialized into my collection object.
string testDataFolder = "testData";
string jsonFileName = "testData.json";
string testJson = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, testDataFolder, jsonFileName));
When I run the unit test, I keep getting an error complaining that my testData.json is not located in the \bin\debug\netcoreapp3.1
location. I don't understand why File.ReadAllText()
keeps looking in that location when I'm telling it to just look in my \Source\Repos\ReposName\Project.Tests\testData
folder. Anyone have any suggestions on how to do this correctly? I must be missing something here. Thank you.