title: Unit Test for Generic function in C#
body: <p>Seems to be a popular question but I haven't found the answer yet, so</p>
  
  <p>To be short, I have a generic function that I need to perform <code>unit test</code> on it, say</p>
  
  <blockquote>
    <p><code>public void T[] DoSomething&lt;T&gt;(T input1, T input2)</code></p>
  </blockquote>
  
  <p>Now I need to test if this function works correctly for int, ArrayList, how can I write unit tests in this case, listing all the cases for T is not an option, I'm thinking of just test int and some class instance ?</p>
  
  <p>I also try to use the auto generated unit test from VS2012, something looks like :</p>
  
  <pre><code>public void DoSomethingHelper&lt;T&gt;() {
      T item1 = default(T);; // TODO: Initialize to an appropriate value
      T item2 = default(T); // TODO: Initialize to an appropriate value
      T[] expected = null; // TODO: Initialize to an appropriate value
      T[] actual = SomeClass.DoSomething&lt;T&gt;(item1, item2);
      Assert.AreEqual(expected, actual);
      Assert.Inconclusive("Verify the correctness of this test method.");
  }
  [TestMethod()]
  public void AddTest() {
      AddTestHelper&lt;GenericParameterHelper&gt;();
  }
  </code></pre>
  
  <p>which is even more confusing to me, what should i put in DoSomethingHelper to initialize variables ? an int, a string or something ?</p>
  
  <p>Can anyone help ? I've heard of Pex and others, but still no one provided me a sample unit test code for this simple function.</p>