How to run NUnit test on Ubuntu from the command line?
I've created file OnlyTest.cs
using System;
using System.Text;
using System.Collections.Generic;
using NUnit.Framework;
[TestFixture]
public class OnlyTest
{
[Test]
public void MyTest()
{
int a = 10;
Assert.AreEqual(10, a);
}
}
According to article Running NuGet command-line on Linux I've downloaded files NuGet.exe and Microsoft.Build.dll
I've run NuGet to install NUnit
$ mono NuGet.exe install NUnit Installing 'NUnit 2.6.4'. Successfully installed 'NUnit 2.6.4'. $ ls -lR .: razem 1668 -rw-rw-r-- 1 mw mw 28861 cze 24 23:45 Microsoft.Build.zip -rw-rw-r-- 1 mw mw 1664512 cze 24 23:42 NuGet.exe drwxrwxr-x 3 mw mw 4096 cze 25 00:29 NUnit.2.6.4 -rw-rw-r-- 1 mw mw 208 cze 25 00:27 OnlyTest.cs ./NUnit.2.6.4: razem 108 drwxrwxr-x 2 mw mw 4096 cze 25 00:29 lib -rw-rw-r-- 1 mw mw 1131 cze 25 00:29 license.txt -rw-rw-r-- 1 mw mw 99004 cze 25 00:29 NUnit.2.6.4.nupkg ./NUnit.2.6.4/lib: razem 720 -rw-rw-r-- 1 mw mw 151552 cze 25 00:29 nunit.framework.dll -rw-rw-r-- 1 mw mw 584600 cze 25 00:29 nunit.framework.xml
Since I'm not sure about compiling and running
Compiling hadn't produce any errors
mcs OnlyTest.cs -target:library -r:NUnit.2.6.4/lib/nunit.framework.dll -out:OnlyTest.dll
But when I try run nunit I get errors like
$ nunit-console OnlyTest.dll -noresult NUnit-Console version 2.6.0.0 Copyright (C) 2002-2012 Charlie Poole. Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. Copyright (C) 2000-2002 Philip Craig. All Rights Reserved. Runtime Environment - OS Version: Unix 3.16.0.30 CLR Version: 4.0.30319.17020 ( Mono 4.0 ( 3.2.8 (Debian 3.2.8+dfsg-4ubuntu1.1) ) ) ProcessModel: Default DomainUsage: Single Execution Runtime: mono-4.0 Missing method .ctor in assembly /[MY_PATH]/OnlyTest.dll, type NUnit.Framework.TestFixtureAttribute Can't find custom attr constructor image: /[MY_PATH]/OnlyTest.dll mtoken: 0x0a000001 Could not load file or assembly 'nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies.
The same goes for nunit-gui
Could not load file or assembly 'nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77'
Check which nunit-console/nunit assemblies that are installed... I assuming it is picking up old assemblies in the GAC.
Lets start from the beginning:
Get the latest and greatest NUnit AND it's Runner tools
curl https://api.nuget.org/downloads/nuget.exe -o nuget.exe
mono nuget.exe install NUnit
mono nuget.exe install NUnit.Runners
Make sure the mono is finding those assemblies first (vs the GAC)
export MONO_PATH=$(PWD)/NUnit.Runners.2.6.4/tools:$(PWD)/NUnit.2.6.4/lib
Create your test example and compile it:
vi OnlyTest.cs #Using the example in your question
mcs OnlyTest.cs -target:library -r:NUnit.2.6.4/lib/nunit.framework.dll -out:OnlyTest.dll
Run it:
mono ./NUnit.Runners.2.6.4/tools/nunit-console.exe OnlyTest.dll -noresult
Output:
Using default runtime: v4.0.30319
NUnit-Console version 2.6.4.14350
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Unix 14.3.0.0
CLR Version: 4.0.30319.17020 ( Mono 4.0 ( 4.3.0 (master/b044a27 Thu Jun 18 15:17:08 PDT 2015) ) )
ProcessModel: Default DomainUsage: Single
Execution Runtime: mono-4.0
.
Tests run: 1, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.0280499 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
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