BeforeTestRun BoDi Dependency Injection bug? #88
-
Hi All, I have recently picked up investigating migrating our test projects from Specflow to Reqnroll but have happened upon an issue, and unsure if this is a known issue/bug or if I am simply missing something. As this is a new project I figured this would be the best place to ask! When using Specflow, I am able to register dependencies in the [BeforeTestRun] hook, as below. Here, I am just registering an instance of my test settings, as an example: Then, say I want to use the test settings in a [BeforeScenario] hook, I am able to inject them via a constructor: This method I have used time and time again, with no issue with the constructor happily injecting that dependency for me from within that container instance: Here is the issue.... when I migrate to Reqnroll (with absolutely no other changes except the package and Using reference), the container instance does not seem to carry over to the [BeforeScenario] hooks! I discovered the issue in an existing test project with many dependencies, but have replicated it on a brand new Reqnroll project with the test settings for ease. Here are my project files with Specflow and with Reqnroll, for reference: Would appreciate any thoughts on this, in the existing test project we have been doing it this way for years and the migration documentation didn't mention anything differently regarding DI. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
If you want to remain test framework independent you should not create a dependency between BeforeTestrun and BeforeScenario as they're not guaranteed to run in the same thread. Just a note of warning as I don't think this approach will work with all test runners. Other than that I remember something in the documentation hinting at this not being a supported approach, but I can't find it anymore. Either I'm mistaken or the warning was removed at some point in the last two years. This is touching on some work that I'm doing to make it possible to resolve scenario specific value retrievers, which also means properly keeping track of the container across the various hooks. That change is a bit slow going as I do have some time I can spend at work on it, but it has been given low priority unfortunately. I'll keep in mind to test this scenario as well if it is not resolved before then :) |
Beta Was this translation helpful? Give feedback.
-
It is out: https://github.com/orgs/reqnroll/discussions/142 closing this topic |
Beta Was this translation helpful? Give feedback.
@bethly-hallows yes, this is in. I'm currently preparing the release. And plan to have it (at least a preview) by tomorrow.