Resharper nunit unit test – Could not find a part of the path

Possibly save 1 hour of your time: There are times when your unit test depends on input file. To access the file when using nunit 3.8.1, you can use TestContext.CurrentContext.TestDirectory.

[Test]
public void LoadFileInUnitTestProject()
{
var doc = new XmlDocument();

doc.Load(TestContext.CurrentContext.TestDirectory + "\\Services\\CountryProfile\\population.query.xml");

Assert.That(doc, Is.Not.Null);

}

Book ReSharper Essentials

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s