Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On OSX with MonoDevelop, Run NUnit Tests from Terminal / Command Line

Given that I create a C# NUnit Test Library called TryTesting in MonoDevelop(MD) (3.0.4.6) on OSX, how should I run these tests from the terminal/command-line (so that I can add them to an automated build)?

I know that the general formula is:

nunit-console .../TryTesting/bin/Debug/TryTesting.dll

or

mono nunit-console.exe .../TryTesting/bin/Debug/TryTesting.dll

However, that alone is insufficient given the environment created when installing MonoDevelop.

I get the following output & error:

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 12.1.0.0
CLR Version: 2.0.50727.1433 ( 2.10.9 (tarball Mon May  7 20:25:51 EDT 2012) )

Missing method .ctor in assembly /private/var/folders/r6/wqmfjz8142z0z9vcg_7k9y140000gn/T/nunit20/ShadowCopyCache/3688_634830482326369170/Tests/assembly/shadow/52c5f76b/6c545c94_3e91abff_00000001/TryTesting.dll, type NUnit.Framework.TestFixtureAttribute
Can't find custom attr constructor image: /private/var/folders/r6/wqmfjz8142z0z9vcg_7k9y140000gn/T/nunit20/ShadowCopyCache/3688_634830482326369170/Tests/assembly/shadow/52c5f76b/6c545c94_3e91abff_00000001/TryTesting.dll mtoken: 0x0a000003
Could not load file or assembly 'nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies.

Upon experimentation, it seems this issue is caused by mismatched nunit versions between /usr/bin and MD. If I download the latest NUnit binaries and replace the nunit.framework reference in my project to point at the downloaded copy, then I can get it to run by using the downloaded nunit-console.exe.

So, perhaps the question is:

  • Should I delete the automatic references to nunit.framework and include my own distribution of NUnit in my source tree?
  • or, Does MonoDevelop have a matching version of nunit-console that I should be calling?
like image 558
Jacob Foshee Avatar asked Sep 12 '12 17:09

Jacob Foshee


People also ask

How do I get NUnit console exe?

The preferred way to download NUnit is through the NuGet package manager. The latest releases of can always be found on the relevant GitHub releases pages.

Where is NUnit console installed?

By default the NUnit installation program places all of the files into the C:\Program Files\NUnit 2.4 directory. In the installation directory there are three sub-directories: bin, doc, and samples. Source code is no longer provided with the binary installation package.

What is NUnit console?

nunit-console is a simple but powerful front-end to NUnit, a testing framework for . NET. It will run all or some tests from the assemblies specified as arguments and display the results. Results can be written in either XML or plain text.


2 Answers

After much experience running unit tests across multiple environments I recommend not referencing nunit.framework that comes with MonoDevelop (or Xamarin Studio). If you only ever run your tests within that IDE it is fine. However, if you run your tests from a command line, a different environment or on a build box then you should have control over your version of NUnit.

Thus, if you create a new NUnit Library from the New Project dialog, you should remove the provided nunit.framework reference and replace it with your own.

Also note that NUnit test runners are very sensitive to the assembly version. So you should keep all of the NUnit binaries together in your source tree. (NUnit-2.6.1/bin weighs in at 7 MB)

It is also worth noting that there are other ways to run the tests, such as the NAnt <nunit2> Task, which will be sensitive to the NUnit version.

Thus, having downloaded NUnit 2.6.1* to the packages directory under my solution directory, the command would be:

mono packages/NUnit-2.6.1/bin/nunit-console.exe TryTesting/bin/Debug/TryTesting.dll

*Footnote: I've not been able to use NUnit 2.6.2 due to a NotImplementedException.

like image 130
Jacob Foshee Avatar answered Oct 05 '22 12:10

Jacob Foshee


I also meet this issue. Then I upgrade version of NUnit Dll. Finally, I can use it. Please refer to the below link: http://nunit.org/?p=download

Thanks.

like image 39
HungNguyen Avatar answered Oct 05 '22 10:10

HungNguyen