Skip to content
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

Why Directory.GetCurrentDirectory() return @"C:\Windows\system32" not TestAssembly Directory? #1768

Closed
bobdog1986 opened this issue Aug 25, 2016 · 2 comments

Comments

@bobdog1986
Copy link

bobdog1986 commented Aug 25, 2016

Hello everyone!
I use NUnit V3.4.1 in a WPF Solution, vs2015, window7-32bit.
When I call Directory.GetCurrentDirectory() in a TestMethod, it return @"C:\Windows"\system32 instead of the TestAssembly's value.
Is it the way NUnit design to be?
Follow are screenshot and code.
1
2

@CharliePoole
Copy link
Contributor

This is covered in the Breaking Changes page of the docs. It's a decision we made when we created NUnit 3.0.

NUnit V2 had a guarantee that the current directory would be the directory that contains your test assembly. In order to guarantee this, we had to change the current directory each time a new assembly was loaded or run. We decided that this was a bad idea, for several reasons:

  1. In general, if you start a program with a certain CD, it really should not be changing it.
  2. It becomes particularly problematic with the introduction of parallel execution.

As explained in the docs, if you need to find out the directory in which the assembly resides, you can use TestContext.CurrentContext.TestDirectory.

Note that if you are using the directory for output, you should use WorkDirectory rather than TestDirectory. WorkDirectory usually is the same as TestDirectory but can be changed from the command-line.

@bobdog1986
Copy link
Author

Thank you for reply.

@rprouse rprouse modified the milestone: Closed Without Action Jan 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants