Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Different test results with ncrunch and NUnit tool
mrt181
#1 Posted : Tuesday, June 7, 2011 12:28:21 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/31/2011(UTC)
Posts: 4
Location: Germany

Thanks: 1 times
I am testing this method:

Code:
public static Base<T> Create(string typeName, string assemblyName) where T : class
        {
            string name = string.Format(
                CultureInfo.InvariantCulture, "{0}`1[[{1}]], {2}", typeName, typeof(T), assemblyName);
            Type type = Type.GetType(name, true);

            return new Derived<T>((BaseImpl<T>)type.GetProperty("Instance").GetValue(null, null));
        }


This test succeeds with NUnit but fails with NCrunch:
Code:
[Test]
        [ExpectedException(typeof(FileNotFoundException))]
        public void Create_throws_FileNotFoundException_if_assembly_can_not_be_found()
        {
            using (Factory.Create<string>(this.typeName, "This.File.Does.Not.Exist"))
            {
            }
        }


Ncrunch expects a FileLoadException but the assembly does not exist??
Remco
#2 Posted : Tuesday, June 7, 2011 6:52:32 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Mrt181,

This is caused by a difference in assembly resolution logic between NCrunch and NUnit.

NCrunch throws a different exception with extra information about the paths checked for the missing assembly. This was implemented for diagnostics, as assembly resolution issues can be horrifically hard to troubleshoot without it.

You can work around this by generalising your exception handling a bit, i.e:

Code:
[Test]
public void Create_throws_FileNotFoundException_if_assembly_can_not_be_found()
{
	try
	{
		Create<string>(this.GetType().Name, "This.File.Does.Not.Exist");
	}
	catch (Exception ex)
	{
		Assert.That(ex is FileLoadException || ex is FileNotFoundException);
		return;
	}

	Assert.Fail();
}


I hope this helps.


Cheers,

Remco
1 user thanked Remco for this useful post.
mrt181 on 6/7/2011(UTC)
mrt181
#3 Posted : Tuesday, June 7, 2011 7:48:57 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/31/2011(UTC)
Posts: 4
Location: Germany

Thanks: 1 times
Ok, that works but feels like a hack.
Shouldn't it behave like nunit, no matter if this is worse or better?
Shouldn't this diagnostic behavior be optional?
Remco
#4 Posted : Tuesday, June 7, 2011 8:22:53 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Agreed - it's not pretty.

There are some strong arguments in favour of aligning this with NUnit. Likely there will be some adjustments made around this in a future release.

Thanks for reporting it :)
otac0n
#5 Posted : Tuesday, June 14, 2011 9:38:16 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/22/2011(UTC)
Posts: 51
Location: Seattle, WA

Was thanked: 7 time(s) in 7 post(s)
Arguably, you should use the `Assert.That(() => { }, Throws.InstanceOf<>());` method, anyways.

You should be able to write your own constraint that would support subclasses, too.

Remco
#6 Posted : Monday, September 5, 2011 7:45:46 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
For anyone interested, this issue should be fixed in the recently released 1.33b.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.044 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download