Resharper Nunit test cannot get the correct current directory

Answered

Hi,

I have a Nunit 3 unit test, in which I need to read a file at the "bib\Debug" directory. I use to use "Directory.GetCurrentDirecotry()" method to get the full path of the "bin\Debug" directory. The "GetCurrentDirectory()" used to return the correct directory path. But now, it returns something like:

C:\Users\User7\AppData\Local\JetBrains\Installations\ReSharperPlatformVs15_c9492c82\TestData\testdata.txt

I have checked the Resharper options, and the "Run tests from" is set to "project output folder". I have also tried to reinstall resharper. But still have this problem.

 

JetBrains ReSharper Ultimate 2017.2.2 Build 109.0.20171006.122324
dotCover 2017.2.20171006.131113
ReSharper 2017.2.20171006.123800

Application Packages:
JetBrains dotCommon Core build 109.0.20171006.122930 on 2017-10-06 12:29:41Z rev git::refs/heads/wave09-eap16-bugfix2::5539f8020496c4580ece97c722a809efe78c5092
.
JetBrains dotCommon ElevationAgent build 109.0.20171006.122930 on 2017-10-06 12:29:41Z rev git::refs/heads/wave09-eap16-bugfix2::5539f8020496c4580ece97c722a809efe78c5092
.
JetBrains dotCommon Native Libraries build 109.0.20171006.122317 on 2017-10-06 12:23:27Z rev git::refs/heads/wave09-eap16-bugfix2::922e72c57ed4a281eedc3677b5166ef93f7572c2
.
JetBrains dotCommon Native Link build 109.0.20171006.122317 on 2017-10-06 12:23:27Z rev git::refs/heads/wave09-eap16-bugfix2::922e72c57ed4a281eedc3677b5166ef93f7572c2
.
JetBrains dotCommon.Psi Navigation build 109.0.20171006.123720 on 2017-10-06 12:37:25Z rev git::refs/heads/wave09-eap16-bugfix2::9115fe90e50f4cb8c8263ca065e690686e82a30c
.
JetBrains dotCommon.Psi UnitTesting build 109.0.20171006.123720 on 2017-10-06 12:37:25Z rev git::refs/heads/wave09-eap16-bugfix2::9115fe90e50f4cb8c8263ca065e690686e82a30c
.
JetBrains dotCommon Remotable build 109.0.20171006.122930 on 2017-10-06 12:29:41Z rev git::refs/heads/wave09-eap16-bugfix2::5539f8020496c4580ece97c722a809efe78c5092
.
JetBrains dotCommon Timeline build 109.0.20171006.122930 on 2017-10-06 12:29:41Z rev git::refs/heads/wave09-eap16-bugfix2::5539f8020496c4580ece97c722a809efe78c5092
.
JetBrains dotCover Core build 109.0.20171006.131113 on 2017-10-06 13:11:28Z rev git::refs/heads/wave09-eap16-bugfix2::1fc3cec93df24a9d5776bd6561c0a1ed1bfe731d
.
JetBrains dotCover Presentation build 109.0.20171006.131113 on 2017-10-06 13:11:28Z rev git::refs/heads/wave09-eap16-bugfix2::1fc3cec93df24a9d5776bd6561c0a1ed1bfe731d
.
JetBrains dotCover VisualStudio build 109.0.20171006.131113 on 2017-10-06 13:11:28Z rev git::refs/heads/wave09-eap16-bugfix2::1fc3cec93df24a9d5776bd6561c0a1ed1bfe731d
.
JetBrains EtwService Core build 109.0.20171006.122852 on 2017-10-06 12:28:57Z rev git::refs/heads/wave09-eap16-bugfix2::52e5d50c536580248a2af62759593c7b5f71dd6c
.
JetBrains Platform Core Ide build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform Core Shell build 109.0.20171006.121620 on 2017-10-06 12:16:34Z rev git::refs/heads/wave09-eap16-bugfix2.
JetBrains Platform Core Text build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform Installer build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform Interop CommandLine build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform Interop dotMemoryUnit Framework build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform Interop dotMemoryUnit Interop.Console build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform Interop dotMemoryUnit Interop.Ide build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform RdProtocol build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform Standalone Shell build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform UIInteractive Ide build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform UIInteractive Shell build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform UIInteractive Text build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Platform VisualStudio build 109.0.20171006.122324 on 2017-10-06 12:23:35Z rev git::refs/heads/wave09-eap16-bugfix2::1924e3442df59919fe7d685c5f532e17ab14d4e1
.
JetBrains Profiler Configurator WPF build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Editor Core build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Editor Windows BehaviorModel build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Editor Windows WPF build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Kernel CleanUp build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Kernel Core build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Kernel InternalLauncher build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Kernel Windows Api build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Kernel Windows Engine build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler Kernel Windows Native Core build 109.0.20171006.123926 on 2017-10-06 12:39:37Z rev git::refs/heads/wave09-eap16-bugfix2::ce88e45c00285451bf4751abadf3aa5e7d80107c
.
JetBrains Profiler Kernel Windows Native Link build 109.0.20171006.123926 on 2017-10-06 12:39:37Z rev git::refs/heads/wave09-eap16-bugfix2::ce88e45c00285451bf4751abadf3aa5e7d80107c
.
JetBrains Profiler Snapshot build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler VsIntegration Core build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Profiler VsIntegration Windows build 109.0.20171006.123131 on 2017-10-06 12:31:42Z rev git::refs/heads/wave09-eap16-bugfix2::aeeda0f841166ef79a9d0d35e60982e8036d62cd
.
JetBrains Psi.Features Core build 109.0.20171006.122931 on 2017-10-06 12:29:44Z rev git::refs/heads/wave09-eap16-bugfix2::ff9b572e2b061a33b4bef6f560b052ba3d6ad7b6
.
JetBrains Psi.Features SolutionBuilder build 109.0.20171006.122931 on 2017-10-06 12:29:44Z rev git::refs/heads/wave09-eap16-bugfix2::ff9b572e2b061a33b4bef6f560b052ba3d6ad7b6
.
JetBrains Psi.Features src build 109.0.20171006.122931 on 2017-10-06 12:29:44Z rev git::refs/heads/wave09-eap16-bugfix2::ff9b572e2b061a33b4bef6f560b052ba3d6ad7b6
.
JetBrains Psi.Features Tasks build 109.0.20171006.122931 on 2017-10-06 12:29:44Z rev git::refs/heads/wave09-eap16-bugfix2::ff9b572e2b061a33b4bef6f560b052ba3d6ad7b6
.
JetBrains Psi.Features UIInteractive Core build 109.0.20171006.122931 on 2017-10-06 12:29:44Z rev git::refs/heads/wave09-eap16-bugfix2::ff9b572e2b061a33b4bef6f560b052ba3d6ad7b6
.
JetBrains Psi.Features UnitTesting build 109.0.20171006.122931 on 2017-10-06 12:29:44Z rev git::refs/heads/wave09-eap16-bugfix2::ff9b572e2b061a33b4bef6f560b052ba3d6ad7b6
.
JetBrains Psi.Features VisualStudio build 109.0.20171006.122931 on 2017-10-06 12:29:44Z rev git::refs/heads/wave09-eap16-bugfix2::ff9b572e2b061a33b4bef6f560b052ba3d6ad7b6
.
JetBrains ReSharper Plugins ReSharperTutorials build 109.0.20171006.123800 on 2017-10-06 12:38:12Z rev git::refs/heads/wave09-eap16-bugfix2::ccf855843ee44c59b99b05536ea803b27e378a71
.
JetBrains ReSharper src build 109.0.20171006.123800 on 2017-10-06 12:38:12Z rev git::refs/heads/wave09-eap16-bugfix2::ccf855843ee44c59b99b05536ea803b27e378a71
.
PowerToys CyclomaticComplexity build 2017.2.0 on 2017-11-02 04:17:37Z.

ReSharper 2017.2.2 Licensed to NIKE Inc., assigned to David Shen. Subscription is valid before 3/12/2018. Perpetual for builds released before 3/13/2017
dotCover 2017.2.2 Free trial period is running. 24 days left
Deployment Packaging Identity: 9.0.20171006.131508
Visual Studio Professional 2017 (version 15.4.27004.2005).

Copyright © 2017 JetBrains. All rights reserved.

 

====================

 

Microsoft Visual Studio Professional 2017
Version 15.4.1
VisualStudio.15.Release/15.4.1+27004.2005
Microsoft .NET Framework
Version 4.6.01038

Installed Version: Professional

Visual Basic 2017 00369-60000-00001-AA158
Microsoft Visual Basic 2017

Visual C# 2017 00369-60000-00001-AA158
Microsoft Visual C# 2017

Visual F# 4.1 00369-60000-00001-AA158
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package 8.9.00809.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.0.30925.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 1.0
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.50921.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.0.30915.0
Azure App Service Tools v3.0.0

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 3.0.17262.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

JavaScript Language Service 2.0
JavaScript Language Service

JetBrains ReSharper Ultimate 2017.2.2 Build 109.0.20171006.122324
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2017 JetBrains, Inc.

Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.50719.1

Microsoft Continuous Delivery Tools for Visual Studio 0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

NuGet Package Manager 4.4.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Python 3.0.17262.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Django support 3.0.17262.1
Provides templates and integration for the Django web framework.

Python - IronPython support 3.0.17262.1
Provides templates and integration for IronPython-based projects.

Python - Profiling support 3.0.17262.1
Profiling support for Python projects.

SQL Server Data Tools 15.1.61707.200
Microsoft SQL Server Data Tools

TypeScript 2.3.5.0
TypeScript tools for Visual Studio

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

VsVim 2.4.1.0
VsVim is a Vim emulator for Visual Studio

 

4 comments
Comment actions Permalink

Hi,

 

I had the same issue and I solved it by changing the Resharper setting:

ReSharper -> Options -> Tools -> Unit Testing -> Test Frameworks -> NUnit -> 

Change setting "NUnit 3: When running tests set Environment.CurrentDirectory to:" FROM "Temporary folder" TO "Test assembly's folder".

Now the GetCurrentDirectory() should return the correct path.

1
Comment actions Permalink

Hello David Shen

 

Thank you for contacting us! Please try sinipelto's solution posted above, it should work out.

0
Comment actions Permalink

Andrey Simukov I have an issue where I am running a test where the class under test uses the following:

Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)

(this is required because when the application runs as a service the "CurrentDirectory" won't work)...

This code and it's test was working with Resharper, but I recently upgraded to: JetBrains ReSharper 2020.3.2 Build 203.0.20201229.111204 built on 2020-12-29

now, my test is broken because it's trying to load the current process 
"C:\\Users\\....\\AppData\\Local\\JetBrains\\Installations\\ReSharperPlatformVs16_0dd60f04\\TestRunner\\netcoreapp2.0"

below is a screenshot of the options I have to change Resharper but I don't see the options that were referred to in this thread...

Help on this is appreciated.

0
Comment actions Permalink

Hello KVNT,

The setting was removed since most users need the test assembly's folder set by default. You may specify the Environment.CurrentDirectory value in your tests' code.

0

Please sign in to leave a comment.