nunit: A bug when using Assert.That() with Is.Not.Empty

I’ve noticed some unexpected behaviour when I use the following code:

// EXPECTED - throws NUnit.Framework.AssertionException
Assert.That(null, Is.Not.Null);

// UNEXPECTED - throws System.ArgumentException
Assert.That(null, Is.Not.Empty);

// EXPECTED - throws NUnit.Framework.AssertionException
Assert.That("", Is.Not.Empty)

// UNEXPECTED - throws System.ArgumentException
Assert.That(null, Is.Not.Null.Or.Empty)

// UNEXPECTED - doesn't throw exception at all
Assert.That("", Is.Not.Null.Or.Empty)

Note that in all cases I would expect NUnit.Framework.AssertionException to be thrown.

I guess this is a bug and I’m wondering if the code marked with // UNEXPECTED has been unit tested?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (18 by maintainers)

Commits related to this issue

Most upvoted comments

@jhamm oh yes, you’re right! It should be Is.Not.Null.And.Not.Empty. But still there is a bug with throwing System.ArgumentException instead of NUnit.Framework.AssertionException when null is passed.