tags:

views:

556

answers:

2
+1  Q: 

Nunit .net vs mono

I have written a simple test application using asp.net mvc with C#. The application uses MySQL by using dblinq to generate linq to MySQL files and the application is working both in windows and linux.

I have now started to use NUnit to test my code, mostly since I need to test if the code working under windows also will work in linux. My NUnit tests runs well under Windows but not under Linux.

This my Windows environment:

NUnit version 2.5.1.9189 Copyright (C) 2002-2009 Charlie Poole. Copyright (C) 2002-2004 James W. Newkirk, Michael C. Copyright (C) 2000-2002 Philip Craig. All Rights Reserved.

Runtime Environment - OS Version: Microsoft Windows NT 5.1.2600 Service CLR Version: 2.0.50727.3053 ( Net 2.0.50727.3053 )

This my Linux environment with the error (Library is my application name):

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 2.6.24.24 CLR Version: 1.1.4322.2032 ( Mono 2.4.2.2 )

** (/usr/local/lib/mono/1.0/nunit-console.exe:4888): WARNING **: The class System.ComponentModel.INotifyPropertyChanged could not be loaded, used in System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 File or assembly name Library.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, or one of its dependencies, was not found.

I can't figure out what I am doing wrong. Do you have any tips? It seems like I need to include System.ComponentModel.INotifyPropertyChanged, I have searched the Internet to see if it is implemented in mono but I can't find any information. Thank you

+3  A: 

Somehow you've started the 1.1 CLR - note "CLR Version: 1.1.4322.2032 ( Mono 2.4.2.2 )"

I'm not sure how you've done that, but I'm pretty sure that's the problem... How exactly are you running NUnit? I suspect that the problem is you're using a version of NUnit compiled against .NET 1.1, so Mono decides to load its own CLR v1.1. Assuming you're explicitly calling the mono binary, try specifying the --runtime argument, like this:

mono --runtime=2.0.50727 (whatever you previously had here)

EDIT: To find out which runtime version you've got, try this Test.cs file:

using System;

class Test
{
    static void Main()
    {
        Console.WriteLine(Environment.Version);
    }
}

Then compile and run it:

$ gmcs Test.cs
$ mono Test.exe
2.0.50727.1433

What version do you get out at the bottom?

Jon Skeet
Maybe I have done something wrong since I have compiled the source myself. I can't however run the code as you mention. Before I run it like this: nunit-console Library.Tests.dllWhen I try as you said: mono --runtime=2.0.50727 nunit-console Library.Tests.dllI get this errorWARNING: The runtime version supported by this application is unavailable.Using default runtime: v1.1.4322Cannot open assembly 'nunit-console': No such file or directory.
unkown
Well the "nunit-console" problem is probably that you mean "nunit-console.exe" but you need to find the runtime version that works... Editing the answer to help.
Jon Skeet
This is pretty strange:$ mono Test.exe2.0.50727.1433But if I run$ mono --runtime=2.0.50727.1433 Test.exe1.1.4322.2032or $ mono --runtime=2.0.50727 Test.exe1.1.4322.2032Regarding nunit I am running nunit-console and not nunit-console.exe I will search to see if I can find the path to nunit-console.exe and try to run that with $ mono nunit-console.exe
unkown
I downloaded nunit and run it instead of using the one coming with mono and i works now.Thank you Jon for helping me out.
unkown
My pleasure - glad it worked eventually :)
Jon Skeet
+2  A: 

Most recent Mono distributions come with two different nunits - one is nunit-console (note no .exe suffix needed, since the packaging supplies convenience shell-scripts), and the other one is nunit-console2. The first is nunit compiled against the CLR 1.1 profile, and the second is nunit compiled against the CLR 2.0 profile.

So, the short version - you needed to use "nunit-console2" instead of "nunit-console" to get the correct nunit version for your tests.

Matt Campbell