views:

373

answers:

1

I'm trying to see if there's a way to get a consistent unit test result across multiple test runners. The current situation is that we have a test assembly where 4 of the tests pass if you run them in NUnit GUI, but fail if you run them using TestDriven.NET or the ReSharper test runner. In the cases where these tests are failing (a System.NullReferenceException is thrown), Application.ExecutablePath appears to be returning the test runner's executable instead of the DLL of the test assembly.

Is there a value other than Application.ExecutablePath I should be using (we're currently using it to get access to the values inside the .config file for the DLL)? What is the NUnit GUI doing (or not doing) that causes it to behave correctly while other test runners are failing?

+2  A: 

You can try using the System.Reflection.Assembly class instead, e.g.

String strPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

There are a few other methods and properties in this class, so I am sure you will find what you need.

Grzenio
Thanks Grzenio. This part of your answer (System.Reflection.Assembly.GetExecutingAssembly().CodeBase) led me to the fix.
Scott A. Lawrence