c# - How do you Unit TEst code which uses String.IsNullOrEmpty? -
do write 2 unit tests? 1 value being null , 1 value being string.empty? similar string.isnullorwhitespace()?
typically i'd use nunit
test cases test these permutations. they'll give coverage of 3 different checks without duplicating 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(); } }
Comments
Post a Comment