Do you write two Unit Tests? One for value being Null and one for value being string.Empty? The similar for string.IsNullOrWhiteSpace()?
Yes, you would typically want to test that all possible classes of inputs (null, empty, whitespace, non-whitespace) get the right outputs.
That means testing both alternatives for String.IsNullOrEmpty()
and all three alternatives 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:
[TestCase("")]
[TestCase(null)]
public class SomeTest(string stringValue)
{
Assert.Throws<ArgumentException>(()=> CheckIfNullOrEmpty(stringValue));
}
public void CheckIfNullOrEmpty(string val)
{
if(string.IsNullOrEmpty(val))
{
throw new ArgumentException();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With