Closed michielboekhoff closed 1 month ago
Okay, so, digging a bit deeper still - it's because we can't access things from the global context inside of our step definitions. In my use-case, have you got any advice on how to achieve this?
@michielboekhoff You can let the ITestRunContext
injected, that is the global context. It has a TestRunContainer
property, if you need the DI container.
@michielboekhoff I have also run into a similar issue while trying to fix #56, but not exactly yours and I could not reproduce your case.
What I have found was that before processing the [GlobalDependencies]
method, the plugin calls the binding registry building here so the binding registry should be ready by that time. Is it possible that the [GlobalDependencies]
method in your case was not in the Reqnroll project but in another project?
@michielboekhoff Ignore my last comment. I was able to reproduce the problem. It seems that any hook fixes the problem, not only [BeforeTestRun]
... Strange... But at the end my fix to #56 also fixes this one, so I'm not sure I want to fully understand how it happened.
OK. I understand it now why it was wrong. Basically the IBindingRegistry
was half finished at the time the [GlobalDependencies]
method was searched for. The step definitions were not processed yet, therefore they cannot report their assemblies. The hooks are immediately processed, so they reported the assembly. This is why the hook was needed. It is fixed now by #139
Reqnroll Version
1.0.1
Which test runner are you using?
xUnit
Test Runner Version Number
2.7.0
.NET Implementation
.NET 8.0
Test Execution Method
Other – PLEASE SPECIFY
Content of reqnroll.json configuration file
Issue Description
Hey there! First of all, thanks so much for this project. I'm really happy that it's been picked up, and I'm really happy to see how active this repo has been recently.
Since I've started using the Autofac plugin, I've been seeing mildly strange behaviour with the
[GlobalDependencies]
attribute. I've been writing integration tests using Testcontainers, and I want to set up a single container to share across all features. To this end, I've got a fairly complexGlobalDependencies
class:GlobalDependencies.cs
ScenarioDependencies.cs
The code annotated with
GlobalDependencies
runs only if I have a[BeforeTestRun]
hook.After some investigation, I believe it's because of an issue in the
BindingRegistryExtensions
class. It appears that, at the time of the global container registration, theIBindingRegistry
is not ready yet (understandable, as it can't map the step definitions). Without any[BeforeTestRun]
hooks,GetBindingTypes
returns an emptyIEnumerable
andGetBindingAssemblies
returns an emptyIEnumerable
too. This ultimately means thatGetMethod
inContainerBuilderFinder.cs
returnsnull
which causes this condition to trigger:(e.g., the code thinks there is no
[GlobalDependencies]
-annotated method!)Steps to Reproduce
Create a project which uses
[GlobalDependencies]
, uses the Autofac plugin but has no hooks. Add an empty[BeforeTestRun]
hook like this:to make the issue disappear.
I can also set up a repro project if desired!
Link to Repro Project
No response