This should be a fairly easy task, since it's common to run unit tests from the console in an automated fashion (CI). Nevertheless, I'm unable to run my unit tests, which use NUnit 2.6.4 installed via NuGet in Xamarin Studio, from the console. Running the tests from Xamarin Studio works flawlessly.
I got a PCL project (FooBar) which I want to test. I therefore created a new test lib project (FooBar.Test), removed the nunit.framework reference and installed an updated version via NuGet. I referenced the PCL project (FooBar) in the test project and wrote a few tests. Running them from Xamarin Studio works like a charm.
Running them from the CLI seems impossible. When I get the tests to run, they fail at points where the test project tries to interact with components from the PCL project.
Attempt 1: Using the NUnit.Runners package from NuGet
% mono packages/NUnit.Runners.2.6.4/tools/nunit-console.exe FooBar.Test/bin/Debug/FooBar.Test.dll NUnit-Console version 18.104.22.16850 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 22.214.171.124 CLR Version: 4.0.30319.17020 ( Mono 4.0 ( 3.12.1 ((detached/b63df7d Mon Mar 16 09:23:13 EDT 2015) ) ) ProcessModel: Default DomainUsage: Single Execution Runtime: mono-4.0 Could not load file or assembly 'file:///Users/o.mader/Projects/FooBar/src/packages/NUnit.Runners.2.6.4/tools/lib/nunit.core.dll' or one of its dependencies. The system cannot find the file specified.
We don't even reach the point where the tests are run.
Attempt 2: Using the
nunit-console.exe shipped with Xamarin Studio
% /Library/Frameworks/Mono.framework/Commands/nunit-console4 FooBar.Test/bin/Debug/FooBar.Test.dll NUnit version 2.4.8 Copyright (C) 2002-2007 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 126.96.36.199 CLR Version: 4.0.30319.17020 ( 3.12.1 ((detached/b63df7d Mon Mar 16 09:23:13 EDT 2015) ) .F. Tests run: 2, Failures: 1, Not run: 0, Time: 0.112 seconds Test Case Failures: 1) FooBar.Test.Extensions.EnumExtensions.TestLocalizedStringDefault : Expected: <System.ArgumentException> But was: <System.IO.FileNotFoundException> at FooBar.Test.Extensions.EnumExtensions.TestLocalizedStringDefault () [0x00023] in /Users/o.mader/Projects/FooBar/src/FooBar.Test/Extensions/EnumExtensions.cs:14 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object,System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object parameters, System.Globalization.CultureInfo culture) [0x00054] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:230
This call shouldn't fail. It runs perfectly fine if I start it in Xamarin Studio.
So, how do I get my NUnit 2.6.4 based library project to run properly from CLI?