My question is How to setup multiple fixtures in one test class?
But the constructor of Zoo class can not handle multiple fixtures.
For exemple:
public class Zoo : IClassFixture<Tiger>, IClassFixture<Wolf>, IClassFixure<Bird>
{
private IFixture fixture;
public Zoo(IFixture fixture)
{
this.fixture = fixture;
}
[Fact]
public void TestAnimal()
{
//Arrange
int actualBonesCount = this.fixture.BonesCount;
int expectedBonesCount = 2;
//Act & Assert
Assert.Equal(expectedBonesCount, actualBonesCount );
}
}
A tiger class
public class Tiger : FixtureBase
{
public Tiger()
{
this.BonesCount = 4;
}
}
A bird class
public class Bird: FixtureBase
{
public Bird()
{
this.BonesCount = 2;
}
}
Test fixture base class
public class FixtureBase : IFixture
{
public int BonesCount { get; set; }
}
And interface
public interface IFixture
{
int BonesCount { get; set; }
}
First of all, let's recall when we want to use Class Fixtures in xUnit:
As you've said, you'd like to reuse methods from
Zoo
test class to implementation tests. Since implementations use inheritance, why not use inheritance for test classes too?Still, I don't really get how would you like for each test to pass as you've hardcoded
BonesCount
to 2 in a generic test.This is solution i came to after your comment. Thank you very much!
;)