Skip to content
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

Migration from Specflow - using undocumented feature #155

Closed
orifn1 opened this issue May 31, 2024 · 6 comments
Closed

Migration from Specflow - using undocumented feature #155

orifn1 opened this issue May 31, 2024 · 6 comments
Labels
question Further information is requested

Comments

@orifn1
Copy link

orifn1 commented May 31, 2024

Reqnroll Version

2.0

Which test runner are you using?

MSTest

Test Runner Version Number

3.2.2

.NET Implementation

.NET 8.0

Test Execution Method

Visual Studio Test Explorer

Content of reqnroll.json configuration file

It is not being used

Issue Description

In Specflow I could make such a call to receive injected context without using [Binding] attribute

TestRunnerManager
    .GetTestRunner()
    .ScenarioContext
    .ScenarioContainer

In Reqnroll I could use

TestRunnerManager
    .GetTestRunnerManager()
    .GetTestRunner(**workerId**)
    .ScenarioContext
    .ScenarioContainer

but ScenarioContext is always null and I do not know where I could take workerId for the current run
Is there any way to reuse Specflow approach

I need this in my custom IValueRetriever class

Steps to Reproduce

just run existing test

Link to Repro Project

No response

@orifn1 orifn1 added the bug Something isn't working label May 31, 2024
@gasparnagy
Copy link
Contributor

Have you used that from a hook? If yes, which one?

@orifn1
Copy link
Author

orifn1 commented May 31, 2024

not just from ValueRetriever without any bindings or using from hook
I then just call
ScenarioContainer.Resolve<MyCustomObject>()

@gasparnagy
Copy link
Contributor

For MsTest the short answer is that you can use System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() as a worker id, but this is only true for MsTest and this API is going to change anyway soon (see #144).

The longer answer:

If you don't run your tests parallel, you can still use ScenarioContext.Current (despite the warning).

For parallel execution cases, it is not possible to guess in general that your ValueRetriever is called from the same thread as your scenario, so this is not generally possible. (Depends on the runner and if you use async or not.)

We plan to make an improvement on assist methods so that they are bound to the scenario context. See https://github.com/orgs/reqnroll/discussions/16.

What you can do as a temporary solution is to make a before scenario hook and save the scenario context to a thread local field until the mentioned feature will be ready. This will work in non-async parallel execution cases as well.

Does that help?

@orifn1
Copy link
Author

orifn1 commented May 31, 2024

Thanks, I will try it next week(if I will have enough time) and inform you

@gasparnagy gasparnagy added question Further information is requested and removed bug Something isn't working labels Jun 4, 2024
@gasparnagy
Copy link
Contributor

I close this issue for now, but please feel free to reopen if there are any updates.

@orifn1
Copy link
Author

orifn1 commented Jun 10, 2024

I could not implement your suggestion quickly, so I decided not to spend time on it (because it is a temporary solution) and wait until the ticket https://github.com/orgs/reqnroll/discussions/16 is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants