I am trying to use NUnit with a Generic TestCase as per this answer: NUnit TestCase with Generics from @György Kőszeg.
However, due to what I test, I need to use a where
constraint with a complex type passed in (class), otherwise the compiler erros with error CS0314.
[TestCase(typeof(SomeClass))]
[TestCase(typeof(SomeOtherClass))]
public void GenericTest<T>(T instance) where T : ISomeInterface
{
Console.WriteLine(instance);
}
SomeClass
and SomeOtherClass
are valid classes that implement ISomeInterface
.
This does fail with the following error:
An exception was thrown while loading the test. System.ArgumentException: GenericArguments[0], 'System.RuntimeType', on '[...]GenericTestT' violates the constraint of type 'ISomeInterface'.
I can't get that to work. If I change it to nameof(SomeClass)
to try it with the string value, I get the same error that String
does not match the constraint.