title: xUnit Abstract Test Class with virtual test methods with parameters
body: <p>I just started with Unit Testing and I'm using xUnit framework. I have an AbstractTest class that defines some abstract test methods which I'll use in every test class. <strong>The problem is in the static field - InsertData</strong>. MemberData in this case InsertData must be static. I can't assign some value to InsertData in the inherited class (TestClass) because I got the error before debugger touch both constructors.</p>
  
  <pre><code>public abstract class AbstractTest&lt;TModel&gt; where TModel : class
  {
     public IRepository&lt;TModel&gt; repo;
     public static IEnumerable&lt;object[]&gt; InsertData;
  
     [Theory]
     [MemberData(nameof(InsertData))]
     public virtual void AbsTestInsert(TModel model)
     {
         try
         {
             repo.AddUpdate(model);
             Assert.True(true);
         }
         catch (Exception ex)
         {
             Assert.True(false, ex.Message);
         }
     }
  }
  
  public class TestClass : AbstractTest&lt;TestModel&gt;
  {
      public TestClass()
      {
          repo = TestRepository();
      }
  }
  </code></pre>
  
  <p>Because I inherit the AbstractTest class I'll have the test.
  <a href="https://i.stack.imgur.com/ylOYq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ylOYq.png" alt="Test class"></a></p>
  
  <p>I can't find a solution to InsertData remain static but to override its value in the inherited class.</p>
  
  <p>I have idea with something like this: </p>
  
  <pre><code>public static IEnumerable&lt;object[]&gt; InsertData() =&gt; Data;
  public abstract/virtual IEnumerable&lt;object[]&gt; Data()
  {
      return ...;
  }
  </code></pre>
  
  <p>But to do this Data also must me static...</p>