-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working directory for tests in console NUnit 3 #1072
Comments
This is by design, as shown here: https://github.com/nunit/nunit/wiki/Breaking-Changes In earlier versions, NUnit changed the working directory. It no longer does so. You can use TestContext.TestDirectory to get the directory that contains the test assembly. |
This breaks a lot of test! Why you changed that? Some of the tests cannot be fixed because runtime code of tested app had dependency that working directory is location of test assembly. |
@imakowski have you tried setting the current working directory to a known directory in an assembly setup? Untested code, but something like; [SetUpFixture]
public class MySetUpClass
{
[OneTimeSetUp]
RunBeforeAnyTests()
{
var dir = Path.GetDirectoryName(typeof(MySetUpClass).Assembly.Location);
Environment.CurrentDirectory = dir;
// or
Directory.SetCurrentDirectory(dir);
}
} |
@imakowski you may not have control over it, but code/applications should not rely on the current working directory being set. Applications should always determine their bin directory with code like I presented above. There are several API calls in Windows that change the current working directory without you being aware of it. Your application could run fine most of the time, but then fail after a user visits a seldom used part of of your application. |
@rprouse this code is not working when is in the shadow copy mode You could use this in that case: |
Alternatively, we provide it for you as TestContext.CurrentContext.TestDirectory. :-) We use the Uri as suggested with a few adjustments for special cases. |
The reason this issue started when the tests were moved upstream was due to a behavior change in the newer nunit. nunit/nunit#1072 This PR uses more explicit resolution for the input & output which is more correct anyways
The reason this issue started when the tests were moved upstream was due to a behavior change in the newer nunit. nunit/nunit#1072 This PR uses more explicit resolution for the input & output which is more correct anyways
The reason this issue started when the tests were moved upstream was due to a behavior change in the newer nunit. nunit/nunit#1072 This PR uses more explicit resolution for the input & output which is more correct anyways
The reason this issue started when the tests were moved upstream was due to a behavior change in the newer nunit. nunit/nunit#1072 This PR uses more explicit resolution for the input & output which is more correct anyways
The reason this issue started when the tests were moved upstream was due to a behavior change in the newer nunit. nunit/nunit#1072 This PR uses more explicit resolution for the input & output which is more correct anyways
there is no TestDirectory property in CurrentContext anymore. i use nunit 3.6.1. there is only WorkDirectory which in my case when i start test from resharper points to wrong place :( |
There is TestContext.TestDirectory. It is a static property. I believe that WorkDirectory is as well? |
well, i can not find it either using visual studio browser or compiler or teleric decompiler. |
I was wrong. It is TestContext.CurrentContext.TestDirectory. However, it is not there on the PORTABLE build. |
|
it is there in 3.6.0 but not in 3.6.1 |
I am looking at the current github repo, and it is exactly as I copied and pasted above. |
Are you sure you are not using the PORTABLE build somehow? |
yes, i'm using it |
Well, that is why it is not there. It is not supported in the PORTABLE build, and never has been, to my knowledge. However, I have never used the PORTABLE build, just run the CI tests against it. |
thank you |
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); |
For people eyeballing for actual code, putting together what @CharliePoole and @rprouse said, it's
For global initializationJust don't enclose the above logic inside any namespace. i.e.
Also, seems the |
Obviously it is better to use |
In NUnit 2.6.4, working dir for my tests was set to corresponding
bin/Debug
directory of test DLL. This allowed me to load external files in tests by relative path.It seems that now working dir is set to the working directory of console runner. Is this by design?
How can I leave test results (*.xml files) in work dir of console runner while having working dir for my tests set to
bin/Debug
?The text was updated successfully, but these errors were encountered: