views:

112

answers:

1

Toy example code:

public abstract class testBase
{
  public testBase()
  {
    //Some common test setup code, which will initialize ManagerClass
  }
}

public class someTests: testBase
{
  public someTests()
  {
    //someTests-specific constructor code.
  }

  [Theory]
  [PropertyData("MyTestData")]
  public void test1(Foo foo)
  {
    //Use foo to do a test
  }

  public static IEnumerable<object[]> MyTestData
  {
    get
    {
      yield return new object[] { ManagerClass.CreateANewFoo(1) };
      yield return new object[] { ManagerClass.CreateANewFoo(42) };
    }
  }
}

In the above example, if I specifically run test1 (I'm using Resharper, but the problem also occurs when I use the xUnit GUI) my test is failing because it seems that neither the testBase nor someTests constructors are being executed. Hence the call to ManagerClass.CreateANewFoo() is throwing a NullReference.

If I run all of the tests in someTests, or any other individual test, the constructor executes as expected and the tests proceed in the expected fashion. The only thing that marks test1 out as different is the fact that it is using the PropertyData attribute.

Any ideas why this is happening/what I'm doing wrong?

+1  A: 

We attempted to reproduce this with xUnit.net 1.5 Beta and cannot.

Brad Wilson
After further discussion on CodePlex (http://xunit.codeplex.com/Thread/View.aspx?ThreadId=65564), I just need to refactor the test in light of the execution order.
BenA