How to run NUnit tests as a stand alone executable?

1

I'm curious how to run NUnit tests not from command line, but as a single executable (console application). I found this article from 2012 that shows how to run it using ConsoleRunner. However, I ran into the following error even though I made sure that the correct version of the nunit.core is installed and referenced.

"Could not load file or assembly 'nunit.core, Version=2.6.4.0, Culture=neutral, PublicKeyToken=ab07c6840cd6369d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"nunit.core, Version=2.6.4.0, Culture=neutral, PublicKeyToken=ab07c6840cd6369d"

So my question is is there any other way on implementing NUnit tests as a single executable? My code snippet is the following,

[TestFixture]
public class Test
{
   public static void Main(string[] args)
   {
      NUnit.ConsoleRunner.Runner.Main( new string[]
      {
          System.Reflection.Assembly.GetExecutingAssembly().Location,
      });
   }

   [Test]
   public void SampleTest()
   {}
c#
visual-studio
unit-testing
nunit
asked on Stack Overflow Nov 24, 2020 by Yunhan Zou • edited Nov 24, 2020 by Wai Ha Lee

1 Answer

3

The trouble with old articles is that authors rarely go back and mark them obsolete. The article refers to NUnit V2, the percursor to NUnit 3. NUnit 3 was a complete rewrite.

The way to create an executable test is to use NUnitLite. You create your test assembly as a console and reference both the nunit framework and nunitlite packages. See the docs for details... https://docs.nunit.org/articles/nunit/running-tests/NUnitLite-Runner.html

answered on Stack Overflow Nov 24, 2020 by Charlie

User contributions licensed under CC BY-SA 3.0