In your tests pass a relative path to the method of the class under test. This avoids resorting to a hard coded full path and as long as your test project is always in the same location relative to your source project it'll work.
e.g. if you have your source set up like this:
\Solution\src\Project\bin\debug\myFile.txt
\Solution\test\TestProject\bin\debug\TestAssembly.dll
The relative path will be @"..\..\..\..\Project\bin\debug\myfile.txt"
Update
I'm not quite sure why your tests are running from a temporary folder. I either use a test runner such as Resharper or set up my test project as follows:
- Open the project properties for the project containing your tests.
- Go to the Debug tab and set the following values:
- Start external program: Enter the location of nunit.exe, e.g. on my PC it's installed to C:\Program Files\NUnit 2.5.5\bin\net-2.0\nunit.exe.
- Command line arguments: Enter the name of your assembly containing your tests followed by the run argument, e.g. TestProject.dll /run.
- Set the project containing your tests as the StartUp Project.
- Hit F5.
This way your tests will always run from bin\debug (depending on how your build is configured), so you can rely on projects always being in the same relative location.