Reputation: 9411
My program deals with input and output files and therefore need to have an access to a folder (included in Visual Studio Project) with existing files, and also create new files and check what's inside.
Tests run on several machines, so absolute path is not an option. Also, I can not self-generate input files.
How I can tell in an NUnit test that I need a folder which is located inside project source tree? NUnit seems to place exe code in some obscure temp folder.
Edit: NUnit 3 is used
Upvotes: 1
Views: 211
Reputation: 6042
Presuming this question refers to NUnit 3, sounds like you need to use TestContext.CurrentContext.TestDirectory
.
This gets the directory the assembly was built to, rather that the temp location where it is ran. (Which Environment.CurrentDirectory
would return.) Documented here. I believe CurrentContext can also sometimes be null, we use TestContext.CurrentContext?.TestDirectory
.
For NUnit 2.X - I believe tests run where they are build, so Environement.CurrentDirectory
should be sufficient.
Upvotes: 1