12 June, 2009
Roel van Lisdonk
2 Comments
0 categories
If you want to Assert that a result string in a NUnit test is not null or empty, use:
Assert.That(string.IsNullOrEmpty(result), Is.False, "Result string must not be null or empty");
Tags: NUnit
2 Replies to “C# – Assert that a string is not null or empty with NUnit”
Leave a Reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Related Posts
How to use entities from an other eSpace in Outsystems
8 October, 2013
Roel van Lisdonk
0 Comments
1 category
Lets assume you have two eSpaces: eSpace_1 eSpace_2 Now you…
Awesome: Visual Studio will minify a css file automatically, when original file is altered.
7 November, 2014
Roel van Lisdonk
0 Comments
1 category
I Just discovered that Visual Studio will automatically re-minify a…
jQuery tip: Add an element as hidden and show on click.
26 April, 2013
Roel van Lisdonk
0 Comments
1 category
If you want to add an element initially as hidden,…
Hi Roel,
I believe you can also do the following (in NUnit 3 at least):
Assert.That(result, Is.Not.Null.Or.Empty, “Result string must not be null or empty”);
Further details:
https://github.com/nunit/nunit/wiki/Breaking-Changes
Thanks,
Mark
Regarding Mark’s comment, that should be
Assert.That(result, Is.Not.Null.And.Not.Empty);
Assert.That(“”, Is.Not.Null.Or.Empty); passes because the empty string is not null, or is empty. In fact, because Is.Not.Null passes, the Or.Empty isn’t even hit.
!string.IsNullOrEmpty is equivalent to !(s == null || s == “”), which is equivalent to s != null && s != “”
Is.Not.Null.Or.Empty is equivalent to !(s == null) || s == “”, which is equivalent to s != null || s == “”
This can also be used for collections.