title: How should I test null and/or empty string parameters in a method?
body: <p>It is common to have classes with methods with string parameters that must be validated agains null or empty, such as this example:</p>
  
  <pre><code>public class MyClass {
  
      public void MyMethod(string param){
  
          if(string.IsNullOrEmpty(param)){
              throw new ArgumentNullException(...);
          }
          //...
      }
  }
  </code></pre>
  
  <p>It's clear that the behavior of the method is the same for both (invalid) values. This is a very common situation, and when it comes to testing these methods, I always doubt about how to do it. I always create two separate tests for these cases:</p>
  
  <pre><code>[TestClass]
  public class Tests {
  
      [TestMethod]
      public void MyMethod_should_fail_if_param_is_null(){
          //...
          myclass.MyMethod(null);
          //...
      }
  
      [TestMethod]
      public void MyMethod_should_fail_if_param_is_empty(){
          //...
          myclass.MyMethod("");
          //...
      }
  </code></pre>
  
  <p>}</p>
  
  <p>But I see too much redundancy. Those tests are exactly the same, with the only difference being the parameter passed to the method. That bothers me very much, since I have to create two tests for each string parameter. A method with 3 parameters would have 6 tests only to test the parameters.</p>
  
  <p>I think this is the right way of testing those parameters, but if I know that 99% of string parameters will be validated the same way, wouldn't it be better just test them for null (or empty) and assume that the behavior in the other case will be the same?</p>
  
  <p>I would like to know what you think about this. I know what I'm asking is more a technical opinion than a technical question, but I think the testing community may have something interesting to say about this situation.</p>
  
  <p>Thank you!</p>