I have a bunch of classes implementing an interface and having a constructor argument.
For this classes i want to write a test with Generic Test Fixture pattern as documented in the nunit docs section: https://docs.nunit.org/articles/nunit/writing-tests/attributes/testfixture.html#generic-test-fixtures
Sample Classes i want to test:
public class ClassToTest: IInterface
{
public ClassToTest(ConstructorArgument arg1)
{
....
}
}
class AnotherClassToTest: IInterface
{
public AnotherClassToTest(ConstructorArgument arg1)
{
....
}
}
TestClass:
[TestFixture(typeof(ClassToTest))]
[TestFixture(typeof(AnotherClassToTest))]
public class TestClass<TClasses> where TClasses : IInterface, new()
{
private IInterface _classUnderTest;
public TestClass()
{
ConstructorArgument args = new();
_classUnderTest = new TClasses(args); //This will not compile
//How to Pass constructor argument args?
}
[Test]
public void Test1()
{
...
}
}
How am i able to pass the necessary constructor arguments to TClasses?
You could use Activator.CreateInstance for that case.
It should look something like: