dario_ramos
dario_ramos

Reputation: 7309

Getting an assembly's directory from an automated test

I'm trying to write integration tests to cover a big refactoring of my application (I'd like to write unit tests but it's quite far from being unit testable). I'm using Visual Studio 2010 SP1, Resharper and NUnit.

My current problem is that I can't find a consistent way to obtain the executing assembly's directory; the two methods I tried work when running the application on its own, or when debugging from Visual Studio, but they fail when running the test from NUnit or Resharper. Here's the code (VB.NET):

'Method 1    
Core.ConfigFile = My.Application.Info.DirectoryPath + "\" + DRA_CONFIG_FILE
'Method 2
Core.ConfigFile = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) + "\" + DRA_CONFIG_FILE

When I debug the test using Resharper, I get something like this, with both methods:

C:\Documents and Settings\Tomas\Local Settings\Temp\0xl3rbd5.4qn\MGClient.Test\assembly\dl3\2a373977\60b182bb_e5c9cc01\DRA.config

(it should be D:\SVN.DRA.WorkingCopy\DRA.Test\Integration\MGClient.Test\bin\Debug\DRA.config)

How can I get the correct path?

Upvotes: 9

Views: 1080

Answers (2)

oleksii
oleksii

Reputation: 35935

You need to disable shadow copying in Resharper:

Visial Studio menu -> Resharper -> Options -> Tools -> Unit-Testing

Deselect Shadow-copy assemblies being tested

Upvotes: 8

VMykyt
VMykyt

Reputation: 1629

When I debug the test using Resharper, I get something like this, with both methods:

C:\Documents and Settings\Tomas\Local Settings\Temp\0xl3rbd5.4qn\MGClient.Test\assembly\dl3\2a373977\60b182bb_e5c9cc01\DRA.config

Switch off shadow copy in NUnit Test Loader Settings - Advanced

Upvotes: 1

Related Questions