Skorunka František Skorunka František - 6 months ago 42
C# Question

How do you Unit TEst code which uses String.IsNullOrEmpty?

Do you write two Unit Tests? One for value being Null and one for value being string.Empty? The similar for string.IsNullOrWhiteSpace()?


Typically I'd use NUnit test cases to test these permutations. They'll give you coverage of the three different checks without duplicating your test code.

For example:

public class SomeTest(string stringValue)
   Assert.Throws<ArgumentException>(()=> CheckIfNullOrEmpty(stringValue));

public void CheckIfNullOrEmpty(string val)
       throw new ArgumentException();