I ended up creating an abstract collection fixture, with a protected constructor that takes the necessary parameter (in my case, the Assembly
). Then I defined small subclasses that have a no-arg constructor that calls the inherited one with the correct argument.
public abstract class BaseCollectionFixture<TFixture> : ICollectionFixture<TFixture>
where TFixture : class
{
protected BaseCollectionFixture(Assembly assemblyUnderTest)
{
// Do my fixture stuff with the assembly
}
}
[CollectionDefinition("Special tests")]
public class ConcreteFixture : BaseCollectionFixture<ConcreteFixture>
{
public ConcreteFixture() : base(typeof(MyClassUnderTest).Assembly) {}
}
Then I use it in a test like this:
public MyClassTests<ConcreteFixture> { ... }