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

MSTest Static FeatureSetup on generated .feature.cs is a bug #96

Closed
regisbsb opened this issue Jun 30, 2011 · 5 comments
Closed

MSTest Static FeatureSetup on generated .feature.cs is a bug #96

regisbsb opened this issue Jun 30, 2011 · 5 comments

Comments

@regisbsb
Copy link

I'm using MSTest.
Lets pretend you have 2 feature files.
Feature file A has two scenarios: scenario 1 and scenario 3.
Feature file B has one scenarios : test 2.
If you have run tests order by name it will run:
Feature A - scenario 1
Feature B - scenario 2
Feature A - scenario 3

The problem is that feature info is setup on line ~33 on the Feature A.feature.cs on static method FeatureSetup.
Calling testRunner.OnFeatureStart(featureInfo);
this static method is called only once I think.

Then the tests runs:
Feature A class is created. scenario 1 runs
Feature B is created. scenario 2 runs.
scenario 3 runs with the wrong feature context from feature b
So when you go back to Feature A - scenario 3 the ObjectContainer.FeatureContext.FeatureInfo is from Feature B.
Then it messes all the StepScoped step definition. I use FeatureInfo to initialize my CSS selector helpers.
A lot of my tests are falling on a random basis depending on the order they run.

I suggest you to change the generator to write TestInitializeAttribute instead of ClassInitializeAttribute before the FeatureSetup method on .feature.cs files. So the feature info is always right.
Maybe is the same problem of #95 issue.

Thank you.

@regisbsb
Copy link
Author

regisbsb commented Jul 1, 2011

You can find an example http://regis.ws/specflow/TestProject1.zip
In my example you have 2 feature files and each have 2 scenarios that depend on FeatureInfo.Title to work.
If you run the tests together and the order of tests mixes tests from diferent feature files 1 test always fail.

@gasparnagy
Copy link
Contributor

i see the problem...
changing the ClassInitializeAttribute to TestInitializeAttribute is not so easy, as this would lead to running all before/after feature specflow event to run before/after each scenario... we need a smarter way, that somehow checks if the current feature is still the current one and run the logic only if it is not...

@regisbsb
Copy link
Author

We could have one method just for kicking specflow event on ClassInitializeAttribute and another method on TestInitializeAttribute just for setting the FeatureContext.
I've tried to setup my enviroment to provide a full fix but without success.
The main ideia is to split FeatureSetup into 2 methods decorated with ClassInitializeAttribute, and other one with TestInitializeAttribute.
That should do the job.

@gasparnagy
Copy link
Contributor

I think i have a fix for this now, you can test it through the build site (build.specflow.org)

@lock
Copy link

lock bot commented Jul 9, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants