Generic collection fixtures #2425
-
@bradwilson I didn't know whether to file this as an issue or discussion, sorry! A generic fixture and support classes: public class Fixture<T> : IAsyncLifetime, IDisposable {
public Fixture() { }
public void Dispose() { }
public Task InitializeAsync() => Task.CompletedTask;
public Task DisposeAsync() => Task.CompletedTask;
}
[CollectionDefinition("collection")]
public class FixtureCollection<T> : ICollectionFixture<Fixture<T>> { }
[Collection("collection")]
public abstract class TestBase<T> {
protected TestBase(Fixture<T> fixture) => _fixture = fixture;
protected readonly Fixture<T> _fixture;
} I stripped down those classes to show a minimal sample (but there is "stuff" in them). And the test class: public class Foo { }
public class Tests : TestBase<Foo> {
public Tests(Fixture<Foo> fixture) : base(fixture) { }
[Fact] public void Test1() { }
[Fact] public void Test2() { }
} Tests fail:
If I make this change then it works, but I can't use it as a collection fixture: //[Collection("collection")] // removed
public abstract class TestBase<T> : IClassFixture<Fixture<T>> { // added IClassFixture I read the docs. Is this use case supported? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
ref CC of this SO question - the question in particular is related to the fact that a |
Beta Was this translation helpful? Give feedback.
-
The answer is: it's not a supported use case, currently. Feel free to open an issue to get it added to v3. |
Beta Was this translation helpful? Give feedback.
-
Thanks - I used the "Create issue from discussion" feature. Issue #2557. |
Beta Was this translation helpful? Give feedback.
The answer is: it's not a supported use case, currently. Feel free to open an issue to get it added to v3.