title: Dependency Injection in Unit Tests
body: <p>I have implemented array based Stack Data Structure along with corresponding Unit Tests. This Stack implements my IStack interface. So at the moment, my UT class looks something like that:</p>
  
  <pre><code>[TestClass]
  public class Stack_ArrayBased_Tests
  {      
      //check against empty collection
      [TestMethod]
      public void IsEmpty_NoElements()
      {
          var myStack = new Stack_ArrayBased_Example1(10);
  
          var exp = true;
          var act = myStack.IsEmpty();
          Assert.AreEqual(exp, act);
      }
  </code></pre>
  
  <p>Now, I am about to implement Linked List based Stack. This Stack will inherit from the same IStack interface.</p>
  
  <p>I would like to Unit Test the linked list Stack as well. Since both are inheriting from the same interface, I should be able to take advantage of already implemented Unit Test, in order to prevent from unnecessary code duplication. </p>
  
  <p>What would be the best way to create two separate Unit Test classes, one for Array based Stack, and another for Linked List based Stack, that would use the same Unit Test methods? I assume Dependency Injection would be an answer, but how I would go about it?</p>