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
- EmptyConstraint - allow null string fix #1171 — committed to jhamm/nunit by jhamm 8 years ago
- EmptyConstraint - allow null string fix #1171 — committed to jhamm/nunit by jhamm 8 years ago
- EmptyConstraint - allow null string fix #1171 — committed to jhamm/nunit by jhamm 8 years ago
- Fix #1171 — committed to nunit/nunit by CharliePoole 8 years ago
- Merge pull request #1254 from nunit/issue-1171 Fix #1171 — committed to nunit/nunit by rprouse 8 years ago
@jhamm oh yes, you’re right! It should be
Is.Not.Null.And.Not.Empty. But still there is a bug with throwingSystem.ArgumentExceptioninstead ofNUnit.Framework.AssertionExceptionwhennullis passed.