I have these two tests:
[TestFixture(Category = "MyCategory")]
public class MyTestFixture
{
private int count = 0;
[SetUp]
public void BeforeEachTest()
{
this.count++;
}
[Test]
public void AssertCountIs1_A()
{
Assert.AreEqual(1, this.count);
}
[Test]
public void AssertCountIs1_B()
{
Assert.AreEqual(1, this.count);
}
}
One of the two tests will always fail because count will be 1 for one of the tests, but 2 for the other test. I know that this is because the count
member exists for the life of the MyTestFixture
instance.
Can I declare that I want count
to only exist for the life of the given test? For instance, is there some attribute I can prepend to count
so that both of these tests succeed?
If not, I can put together a workaround that keeps a dictionary that maps test names to counts. I'd rather avoid that if I can though.