February 16, 2021

Using Test Files in a Unit Test with NUnit

Insert the files into the project under a new directory say “TestData”. Include them in the project and change the build action on each file such that the “Copy to Output Directory” option should be “Copy if newer”.

Somewhere in your test:
// Create a path to the TestData directory using the 
// NUnit “TestContext.CurrentContext.TestDirectory” property
private string TestFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData");
// Now you have access to the files
string testFilePath = Path.Combine(TestFilePath, @"TestFile1.mib");

No comments: