[Mono-list] NUnit support for generics?

Andy Waddell awaddell at fnfr.com
Tue Sep 20 17:52:59 EDT 2005


Thanks.  

This was working like a champ for me (I edited the config file to use
2.0 first).  The code below works fine in 2.0 if compile as a console
application (no NUnit), but if invoked via nunit-console, it depends on
the ordering of the lines in my config file.  With the config file
modified to use 2.0 first it crashes, but with the original config file
(1.1) it is fine.  Unfortunately the code I really need to test has this
Dns stuff as well as classes that use Generics... so I'm stuck for now. 

I've now run into a problem with the following trivial test case:

// Class1.cs
using System;
using System.Text;
using System.Net;
using NUnit.Framework;

namespace GetHostByNameNUnitTest
{
	[TestFixture]
	public class Class1
	{
		[Test] 
		public void TestDns()
		{
			IPHostEntry hostInfo =
Dns.GetHostEntry("localhost");

			Console.WriteLine("Host name : " +
hostInfo.HostName);
			Console.WriteLine("IP address : " +
hostInfo.AddressList[0]);
		}
	}
}

[awaddell at AWLNX GetHostByNameNUnitTest]$ mcs -target:library
-out:GetHostByNameNUnitTest.dll  -reference:nunit.framework Class1.cs
[awaddell at AWLNX GetHostByNameNUnitTest]$ nunit-console
GetHostByNameNUnitTest.dll 
NUnit version 2.2.0
Copyright (C) 2002-2003 James W. Newkirk, Michael C. Two, Alexei A.
Vorontsov, Charlie Poole.
Copyright (C) 2000-2003 Philip Craig.
All Rights Reserved.

OS Version: Unix 2.4.21.32    Mono Version: 2.0.50215.16

.F

Tests run: 1, Failures: 1, Not run: 0, Time: 0.129971 seconds

Tests run: 1, Failures: 1, Not run: 0, Time: 0.129971 seconds

Failures:
1) GetHostByNameNUnitTest.Class1.TestDns : System.NullReferenceException
: Object reference not set to an instance of an object
in <0x00000> <unknown method>
in (wrapper managed-to-native) System.Net.Dns:GetHostByName_internal
(string,string&,string[]&,string[]&)
in <0x00037> System.Net.Dns:GetHostByName (System.String hostName)
in <0x00058> System.Net.Dns:Resolve (System.String hostName)
in <0x0000a> System.Net.Dns:GetHostEntry (System.String
hostNameOrAddress)
in <0x00010> GetHostByNameNUnitTest.Class1:TestDns ()
in <0x00000> <unknown method>
in (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke (object,object[])
in <0x0008d> System.Reflection.MonoMethod:Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] paramete
rs, System.Globalization.CultureInfo culture)


If I flip the lines in the config file back to have 1.1 run first this
test runs cleanly:

[awaddell at AWLNX GetHostByNameNUnitTest]$ nunit-console
GetHostByNameNUnitTest.dll 
NUnit version 2.2.0
Copyright (C) 2002-2003 James W. Newkirk, Michael C. Two, Alexei A.
Vorontsov, Charlie Poole.
Copyright (C) 2000-2003 Philip Craig.
All Rights Reserved.

OS Version: Unix 2.4.21.32    Mono Version: 1.1.4322.573

.Host name : AWLNX.fnfr.com
IP address : 127.0.0.1


Tests run: 1, Failures: 0, Not run: 0, Time: 0.09918 seconds

Tests run: 1, Failures: 0, Not run: 0, Time: 0.09918 seconds


[awaddell at AWLNX GetHostByNameNUnitTest]$ 

--Andy Waddell 

-----Original Message-----
From: Kamil Skalski [mailto:kamil.skalski at gmail.com] 
Sent: Thursday, September 15, 2005 9:52 AM
To: Andy Waddell
Cc: mono-list at lists.ximian.com
Subject: Re: [Mono-list] NUnit support for generics?

I had the same problem and created a patch some time ago:
http://lists.ximian.com/pipermail/mono-devel-list/2005-September/014598.
html

Unfortunately there is some design issue I was not able to solve - we
would need to mark nunit dll with different version for 1.0 and 2.0
profiles in order to put it into GAC. Otherwise during installation
they are put into the same place and one version overwrites the other
(note that this is just a design issue, the nunit-console still works
with mixed version assemblies).

You can make nunit-console usable on 2.0 using one of the steps:
- delete nunit-console.exe.config files, compile your test dlls by
referencing exact path of 1.0 installed dlls
or
- apply my patch and watch it working
or
- just edit config file to use 2.0 first and reference exact patch of
dlls 

Anyone have idea how to make the issue solved in an elegant way and
ideally make the solution acceptable by nunit.org people?

2005/9/15, Andy Waddell <awaddell at fnfr.com>:
>  
>  
> 
> I've been trying to use the nunit.framework and nunit_console.exe to
do some
> unit testing on code that contains generics (and was therefore compile
with
> gmcs).  I'm getting the feeling that this is not supported.  First
off, I
> noticed that gmcs can't find the nunit assembly when
> -reference:nunit.framework is on the compile line (while mcs can).  I
forced
> the issue there by putting the fully qualified path to the dll on the
> compile line,  but when I run nunit_console.exe to test some simple
code
> (that happens to use generics), it always bombs out.  I write my own
main()
> to invoke the methods, it works fine.  
> 
>   
> 
> Can anyone shed some light on this issue? 
> 
>   
> 
> --andy 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> 
> 
> 


-- 
Kamil Skalski
http://nazgul.omega.pl


More information about the Mono-list mailing list