-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xUnit ICollectionFixture<TFixture> injects new instance of TFixture into steps instead of pre-initialized one. #1430
Comments
I've check current implementation and it seems that we should register this TFixture in xUnit generated code like we already do for ITestOutputHelper: A problem that namespace of this TFixture is unknown, it's somewhere in custom user code, so I don't know how to use it. All info that we have in generated code is [Xunit.Collection("SampleCollection")], it's not even a type but just a collection name. Native xUnit runner use reflection to get collection class by that name and then to find TFixture class from collection class. Just ideas:
|
How is IAsyncLifetime used in XUnit? I don't know this interface. |
"A new IAsyncLifetime interface is available, which can be placed onto test classes, class fixtures, and collection fixtures. This allows asynchonous initialization (InitializeAsync) and cleanup (DisposeAsync)." Current behaviour: with adding of @xunit:collection(SampleCollection), xunit recognize collection, then recognize collection TFixture and if IAsyncLifetime added, run InitializeAsync for this TFixture. Basically, it is for the same purpose as [BeforeTests] tag in specflow/cucumber. |
Thanks for raising this issue. Any idea when this will be fixed or any workaround in place? |
|
Namaste!
I guess the option №3 is better because:
In case of the option №1 we should trust to the user that the name value of
but like this:
The new tag Or even better add Any other suggestions? |
Any plans on addressing this issue? |
You can write RuntimePlugin and GeneratorPlugin yourself overrride XUnit2TestGeneratorProvider. I wrote own exacly like the option №3. But I had to use reflection to invoke "FeatureStart Event" after registering in featureContainer. |
SpecFlow Version:
Used Test Runner
Version number: 3.0.169 - beta
Visual Studio Version
Are the latest Visual Studio updates installed?
.NET Framework:
Test Execution Method:
<SpecFlow> Section in app.config
Repro Project
https://github.com/sphinxy/SpecFlow3Core.XunitPlayground
Issue Description
Native Xunit runner supports ICollectionFixture, where TFixtureis instantiated once per collection and later can be injected to tests.
If we use this approach via specflow xUnit runner with adding tag @xunit:collection(SampleCollection) to support collection and injection TFixture, TFixture is instantiated twice - once for before collection run as expected (by xunit.execution.dotnet.dll!Xunit.Sdk.XunitTestCollectionRunner.CreateCollectionFixture.AnonymousMethod) and then another instance once again (by BoDi.dll!BoDi.ObjectContainer.CreateObject() )
for injecting into specflow steps.
BoDi should reuse existing instance
Steps to Reproduce
Use Xunit 2 runner. Create sample specflow feature and steps. Create Xunit ICollectionFixture and force specflow to use it via @xunit:collection tag in feature file.
Inject TFixture into steps constructor
Check by debug that TFixture is created twice.
Extra: implement IAsyncLifetime in TFixture and check that second instance retrieved in steps doesn't calls InitializeAsync method but first instance for collection do.
The text was updated successfully, but these errors were encountered: