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

Difference between net5.0/net6.0 and netframework 4.7.2 in test tear down #4688

Open
StarWars999123 opened this issue Apr 12, 2024 · 5 comments

Comments

@StarWars999123
Copy link

StarWars999123 commented Apr 12, 2024

Hi,

I noticed a difference during the tear down of netframework (4.7.2) and netcore (net5.0 (Update: appared as well with net6.0)) test projects:
My previously set variables are not longer accessible and the classes (e.g. a System.Configuration.ConfigurationElement with some temporary variables) get reinitialized. Theirby I loose right now some important information, that persists in netframework projects.

I use specflow.Nunit on top, but I assume, that this is a behaviour difference cause by NUnit.
The accessing TearDown method is the following Specflow hook:

 [AfterScenario(Order = 1000)]
 public void AfterScenarioTestEnd(ScenarioContext scenarioContext, ISpecFlowOutputHelper _specFlowHelper)
 {}

and during debugging, it gets called with the following stack trace.
image

I couldn't find any documentation so far about differences between netframework and netcore, but my tests, showed, that there is a difference in the behaviour. How should this be fixed?

Thank you in advance :)

@manfred-brands
Copy link
Member

@StarWars999123 I presume you are NUnit version 3.xx? Version 4.xx does not support .net core 5.0, only 6.0.
Do you see a different stack trace between .net core 5.0 and .net framework?

Do you use any (Default)TimeOut as that behaviour is different, although I don't see that in your stack trace.

@stevenaw
Copy link
Member

@StarWars999123 Can you share a minimal repro? It should be as small as possible while still able to run "as-is" to make it easier for the team to investigate.
One option that makes it easy for us to investigate is to submit it as a PR to #4688

@StarWars999123
Copy link
Author

Yes, I am using Nunit 3.13.3 still. Debugging showed a different time of initialization of those classes. I use it together with Specflow (3.9.74), but due to the initialization I would assume its still an Nunit topic.
In the method given above I try to access the a path variable from a singleton instance (that might not be as single as the name suggests. see below.)
From what I saw so far, I would assume that the singletons instance gets created ouf of two different contexts. The first instance for the test setup, where e.g. the Scenario name gets put into the requested variable and another instance in the afterscenario hook.
With NET472 it looks like the instances for both contexts get initialized during startup of the test. That allows the variable containing the scenario name to be still set.
While with NET5.0 it seems like the second instance gets created during shutdown, where the scenario name is not longer known.

I can try to setup an example project, but this may take some time.

@stevenaw
Copy link
Member

Thanks @StarWars999123
Sorry, a bit of a poor link there in my previous message. The option I meant to suggest for a PR is to our "issues" repo: https://github.com/nunit/nunit.issues

A repro will help us understand a few things including how you're managing configuration, what runner you may be using (ex: console or the adapter + testhost, etc).

@StarWars999123
Copy link
Author

StarWars999123 commented Apr 16, 2024

Thanks @StarWars999123 Sorry, a bit of a poor link there in my previous message. The option I meant to suggest for a PR is to our "issues" repo: https://github.com/nunit/nunit.issues

A repro will help us understand a few things including how you're managing configuration, what runner you may be using (ex: console or the adapter + testhost, etc).

Ok, did that. See: nunit/nunit.issues#5
Using the project you should be able to discover a difference during the initialization. While with Net4.7.2, a property gets initialized twice on startup, NET5.0/NET6.0 causes an initialization after the test already failed. As result, the variable stays empty.

@StarWars999123 StarWars999123 changed the title Difference between net5.0 and netframework 4.7.2 in test tear down Difference between net5.0/net6.0 and netframework 4.7.2 in test tear down Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants