I have written a piece of optimized code that contains special cases for null and empty strings. I am now trying to write a unit test for this code. In order to
null
You can use the Obsolete method String.Copy
string s1 = ""; string s2 = String.Copy(""); Assert.IsTrue(s1.Length == 0 && s2.Length == 0); Assert.IsTrue(!ReferenceEquals(s1, s2));