You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the fixture requiring another fixture doesn't work, throwing an exception.
Xunit.Sdk.TestPipelineException
Class fixture type 'Playground.Tests.FixtureB' had one or more unresolved constructor arguments: FixtureA fixtureA
at Xunit.v3.FixtureMappingManager.GetFixture(Type fixtureType) in /_/src/xunit.v3.core/Utility/FixtureMappingManager.cs:line 164
at Xunit.v3.FixtureMappingManager.InitializeAsync(IReadOnlyCollection`1 fixtureTypes) in /_/src/xunit.v3.core/Utility/FixtureMappingManager.cs:line 224
publicclassFixtureA{publicstringA{get;privateset;}publicFixtureA(){A="Can";}}publicclassFixtureB:IClassFixture<FixtureA>{publicstringB{get;privateset;}publicFixtureB(FixtureAfixtureA){B=fixtureA.A+" we make this work?";}}publicclassMyTests:IClassFixture<FixtureB>{privatereadonlyFixtureB_fixtureB;publicMyTests(FixtureBfixtureB){_fixtureB=fixtureB;}[Fact]publicvoidTest(){Assert.NotEmpty(_fixtureB.B);}}
I'm trying to share and compose some functionality used across tests. The only sketchy way I found of doing this is using TestContext.Current.GetFixture, but this heavily relies on interface implementation order and just doesn't feel right.
publicclassFixtureA{publicstringA{get;privateset;}publicFixtureA(){A="Can";}}publicclassFixtureB:IAsyncLifetime{publicstringB{get;privateset;}=null!;publicFixtureB(){}publicasyncValueTaskInitializeAsync(){varfixtureA=awaitTestContext.Current.GetFixture<FixtureA>();ArgumentNullException.ThrowIfNull(fixtureA);B=fixtureA.A+" we make this work?";}publicValueTaskDisposeAsync()=>ValueTask.CompletedTask;}// will work ONLY if IClassFixture<FixtureA> is implemented before IClassFixture<FixtureB>publicclassMyTests:IClassFixture<FixtureA>,IClassFixture<FixtureB>{privatereadonlyFixtureB_fixtureB;publicMyTests(FixtureBfixtureB){_fixtureB=fixtureB;}[Fact]publicvoidTest(){Assert.NotEmpty(_fixtureB.B);}}
Any chance it will be implemented in xUnit? Other language frameworks allow fixtures to request other fixtures (rstest, pytest) to form complex object initialization.
The text was updated successfully, but these errors were encountered:
I would be willing to look at a PR for this, yes. It's not currently a priority for me to work on, which is a great reason for someone else to do the work. 😂
neistow
changed the title
Fixtures can not request other fixtures
Composable fixtures support
Feb 16, 2025
Currently, the fixture requiring another fixture doesn't work, throwing an exception.
I'm trying to share and compose some functionality used across tests. The only sketchy way I found of doing this is using
TestContext.Current.GetFixture
, but this heavily relies on interface implementation order and just doesn't feel right.Any chance it will be implemented in xUnit? Other language frameworks allow fixtures to request other fixtures (rstest, pytest) to form complex object initialization.
The text was updated successfully, but these errors were encountered: