2

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.

ssthor22
  • 55
  • 4
  • Does this answer your question? [Copying files into the application folder at compile time](https://stackoverflow.com/questions/747941/copying-files-into-the-application-folder-at-compile-time) – Hayden Mar 24 '21 at 23:42
  • That's a good start. I'll dig into this more. Thank you. – ssthor22 Mar 24 '21 at 23:54

0 Answers0