title: Is there a practical way to reuse a set of test methods against different stubs in the Microsoft Unit Test Framework?
body: <p>I am using the Microsoft Unit Test framework under Visual Studio 2012 to test a C# class that represents a data access layer towards a database of some kind.</p>
  
  <p>In order to be able to unit test it, I have created a stub that the class uses instead of said database.
  My test class has the following structure:</p>
  
  <pre><code>[TestClass]
  public class UnitTests {
  
      MyStub stub;
  
      [TestInitialize]
      public void InitializeContext() { // Construct stub  }
  
      [TestCleanup]
      public void CleanupContext() { // Dispose stub }
  
      [TestMethod]
      public void Test1() { ... }
  
      [TestMethod]
      public void Test2() { ... }
  
      ...
  }
  </code></pre>
  
  <p>It works fine.</p>
  
  <p>I would now like to write a second test class that performs the same tests against a different stub, therefore I'd like to reuse the code, but I'm unable to achieve this through inheritance (inheriting <code>UnitTests</code> and overriding both <code>InitializeContext()</code> and <code>CleanupContext()</code>) because the <code>TestMethod</code> attribute appears not to be inheritable.</p>
  
  <p>Is there a practical way to achieve this at all? If so, which one?</p>