7

I'm trying to set up simple NUnit project in Visual Studio 2012 Express using NuGet manager. From PROJECT-> Manage NuGet Packages I installed NUnit (framework) and wanted add NUnit.Runner but during installation I'm receiving:

'NUnit.Runners 2.6.2' already installed.

Ok, but when I go to the TOOLS->Library Package Manager->Manage nuGet Packages for Solution both NUnit (framework) and NUnit.Runners are displayed as installed.

I can use NUnit framework in the code but when I'm trying to run tests the old 'Test Explorer' stays and doesn't show anything. Tests are not invoked neither.

Am I missing something in VS2012 or NUnit configuration?

Michal
  • 3,218
  • 2
  • 25
  • 44

3 Answers3

6

As I've found out Visual Studio Express does not support project extensions (forbidden and disabled by Microsoft). So it seems there's no option to use NUnit without some workarounds. So far I installed full version and there NUnit runner works as expected.

Michal
  • 3,218
  • 2
  • 25
  • 44
5

You could also use the approach sombody mentioned in the comments of this blog post:

  1. Add a reference to nunit-console-runner in your test assembly.

  2. In your test assembly, make a class with the following one liner (see below)

  3. Open your test assembly's properties. For example, right-click on the assembly and select Properties.

    1. On the Application tab, select Output Type: Windows Application; and Startup Object: NUNitConolseRunner (the file above).

    2. On the Debug tab, enter the .csproj file name in Command Line Arguments; and browse to the folder of the .csproj file in Working Directory.

  4. Save everything, set a breakpoint and run using F5 or the green arrow button.

Code:

using System;
namespace MotorExampleTests
{     
    // Written by blokeley
   class NUnitConsoleRunner
   {

     [STAThread]
     static void Main(string[] args)
     {
         NUnit.ConsoleRunner.Runner.Main(args);
     }
   }
}
tobsen
  • 5,328
  • 3
  • 34
  • 51
  • I tried this approach but couldn't get it to work. So I figured out a way to make it work. What I did instead was create a separate console project and then run my tests from the Main method by running the following line: `NUnit.ConsoleRunner.Runner.Main(new string[] {@"C:\myprograms\mysolution\MyProject.Test\bin\Debug\MyProject.Test.dll" });` – FernandoZ Feb 27 '15 at 15:37
  • Also this allows me to keep my tests as a dll instead of an exe as the post above suggests. – FernandoZ Feb 27 '15 at 15:39
  • Instead of hardcoded paths you can get the path via `System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)` – tobsen Mar 04 '15 at 08:26
4

Why not use the built in testrunner in VS2012 and add the nunit testadapter via the extension manager?

Ols1
  • 321
  • 3
  • 15