Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 754
dario_ramos Avatar asked Jan 03 '12 19:01

dario_ramos


2 Answers

You need to disable shadow copying in Resharper:

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

Deselect Shadow-copy assemblies being tested

like image 180
oleksii Avatar answered Nov 01 '22 09:11

oleksii


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

like image 31
VMykyt Avatar answered Nov 01 '22 08:11

VMykyt