9
votes

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?
3
On OSX monodevelop will load the nunit assemblies from: /Applications/MonoDevelop.app/Contents/MacOS/lib/monodevelop/AddIns/NUnit/ And then it will run the tests from code using the RemoteTestRunner, hence it newer calls nunit-console.exe and don't need. I would recommend that you just update the references to the newest version of NUnitjakobandersen

3 Answers

4
votes

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.

2
votes

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.

0
votes

I had a similar problem.

I removed explicit reference (.dll) and I installed NUnit by Nuget package.

Works for me.