Debugging Nunit tests inside VS2010 Express

I wrote a bunch of unit tests inside the VS2010 Express, and tests are tests that they sometimes fail. Since VS express editions do not allow plugins to run, I can't just deploy TestDriven.Net or the equivalent and debug the tests. To try to get around this, I converted my test build to a console application and made the main method as follows:

class CrappyHackToDebugUnitTestInVSExpress { public static void Main() { AppDomain.CurrentDomain.ExecuteAssemblyByName( @"C:\Program Files\NUnit 2.5.5\bin\net-2.0\nunit-console.exe", new [] { Assembly.GetExecutingAssembly().Location, "/framework:4.0" }); } } 

In theory, I should be able to run this, set breakpoints in my test. If this worked, this would be an acceptable job, but I keep getting the following:

 FileLoadException Could not load file or assembly 'C:\\Program Files\\NUnit 2.5.5\\bin\\net-2.0\\nunit-console.exe' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) 

Now the file exists and when started manually, nunit-console works fine. What could be my problem?

+9
unit-testing visual-studio nunit
Jun 08 '10 at 18:34
source share
3 answers

I played with your concept, and it seems that the problem is not with the file upload, but from the dependencies.

I used the following modified code:

And the error was actually not in finding nunit.core.dll, which is located in the / lib directory.

  try { String NUnitPath = @"C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit-console.exe"; AssemblyName asmName = System.Reflection.AssemblyName.GetAssemblyName(NUnitPath); AppDomain.CurrentDomain.ExecuteAssemblyByName(asmName, new[] { Assembly.GetExecutingAssembly().Location, "/framework:4.0" }); } catch (Exception ex) { Trace.WriteLine(ex.Message); Trace.WriteLine(ex.StackTrace); } 

(I like getting System.Reflection.AssemblyName because you can check and see that everything is in order to erase the path to the raw file.)

A quick bulk copy (xcopy nunit. *. Dll) to my debug directory of test projects, and everything went fine. (This should be trivial to find the required minimum dependencies)

Tested in VC # 2010 Express using NUnit 2.5.7 (breakpoints work, but I did not play with other parameters.) Although I'm sure that you can make it passable build with it.

Hurrah!

PS - The first post is here, so I am a little untested regarding how to format blocks of code. Sorry in advance.

+6
Aug 03 '10 at 1:15
source share
— -

Basically, you need to convert your assembly to a Windows Forms application, add the nunit-gui-runner.dll assembly reference and change your Main method to look like this:

  [STAThread] static void Main() { NUnit.Gui.AppEntry.Main(new string[] { Assembly.GetExecutingAssembly().Location }); } 

here is another example:

 ... using NUnit.Gui; namespace __libs { class Program { [STAThread] static void Main(string[] args) { NUnit.Gui.AppEntry.Main(new string[] { @"C:\test\bin\Debug\test.exe" }); } } } 

This will allow you to go into certain tests, but it is not very suitable for the red green cycle, so you will want to use this only for debugging, and not in other circumstances.

+7
Sep 22 '10 at 19:10
source share

I had a similar problem trying to debug unit tests in VS C # express. It is not easy to get it to work correctly, but then I found out about this project template. Works great in C # Express!

http://visualstudiogallery.msdn.microsoft.com/b8a7a8fa-9f5a-4b9b-8e8b-8839a4364f26?SRC=VSIDE

C # Project Template

Integrated tests with Visual Studio, including Visual C # Express version

Standalone NUnit console runner. Let me write test devices and test, run from Visual Studio, simply by pressing F5 (debugging test support), or Ctrl-F5, a free run with the results in the console window. In case of test failure, an audible signal indicates.

Contains important NUnit modules for launching a test project. No external dependencies. Just create a new project using the NUnit Test Application template.

+2
Jun 14 2018-12-12T00:
source share



All Articles