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?
You need to disable shadow copying in Resharper:
Visial Studio menu -> Resharper -> Options -> Tools -> Unit-Testing
Deselect Shadow-copy assemblies being tested
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With