You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inherited SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0/4.0.0-beta.1 #4554
Hi folks, we just updated our unit test project to use the 3.14.0 NuGet package, and now our tests are failing because it appears that the SetUpFixture marked classes are no longer running. Has anyone else seen this behavior? Thanks.
I was able to identify what the cause is for us - this change - #4158 - to make the attribute not inheritable broke things. We had a global namespace class that is meant to apply a shared/inherited class's SetUpFixture logic. This works in 3.13.3 but won't in 3.14.0. Adding the [SetUpFixture] attribute to this top level class fixes it for us. But this may trip some other folks up. Happy to close this since it appears this is an intentional change to lock down the API a little. Sorry for the noise! Thanks everyone.
Interesting, but not sure I follow the logic. You had your own setupfixtureattribute, that derived from the nunit setupfixture. Was that so that it should be easier to apply this other places, other assemblies or namespaces?
And, you solved it by marking that class as a Setupfixture instead ?
Interesting, but not sure I follow the logic. You had your own setupfixtureattribute, that derived from the nunit setupfixture. Was that so that it should be easier to apply this other places, other assemblies or namespaces? And, you solved it by marking that class as a Setupfixture instead ?
We have multiple test projects, and one "shared" test project (which is referenced by all the other test projects). We wanted a class in our shared project marked with [SetUpFixture] to run for all of our test projects.
Pseudo code Example of what's in the shared project:
This works in previous version because the attribute gets inherited in our project-specific classes. To get the latest version working again, I added [SetUpFixture] to my SpecificProjectSetup classes.
To be fair, we just came up with this sort of structure ourselves and saw it work, but maybe there's a better way to have a "shared" setup class like we want?
Now, marking your derived class with the attribute will of course make it more visible that this actually is a Setupfixture, so for future maintainability it could be nice to have it there. But, apart from that, your former way looks good too.
Sorry, I'd stepped away from PC after my last message and I'm not back yet. I'm hazy on the original discussion that led to that issue but the belief at the time is that there were other mechanisms preventing it from being visible on derived classes.
Sounds like reverting 3.14 is warranted but I'd like to take a closer look before we revert from 4.0. I can get a PR up tonight
Having dug a bit more, it looks like this originated based on a discussion in #3937
It seems that this inheritance -based behavior wasn't working at that time. The issue requested adding it and Charlie mentioned in there that the attribute wasn't intended to be used on a base class. There's a mention of documentation update attempts to clarify this, but at the time and even today I can't find them.
Based on the age of the issue, the version of the framework was at most 3.13.2, so I think it's likely that this started to work in a subsequent release. Though it does seem to be, quite literally, undocumented behavior.
Since it had been working in 3.x then I still think we should rollback the changes there to retain existing behavior. But since it seemed like the last discussion about it was that it shouldn't work makes me hesitant to change 4.0 unless we agree it should actually work there. In either event, we should probably update documentation and tests based on the desired direction.
@nunit/framework-team How do we want this to behave in 4.0?
EDIT: I'll open another issue to track the discussion for 4.0, to which we can also associate any Relevant tests or documentation updates
@nicholashead I'm just seeing your earlier comment now. We have a pretty high bar for avoiding accidentally breaking changes, so I'm happy to at least get a PR up for another team member to review and consider.
I'm glad you were able to work around it so quickly in your case 🙂
changed the title [-]SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0[/-][+]SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0/4.0.0-beta.1[/+]on Nov 24, 2023
changed the title [-]SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0/4.0.0-beta.1[/-][+]Inherited SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0/4.0.0-beta.1[/+]on Dec 1, 2023
Activity
stevenaw commentedon Nov 22, 2023
Thanks for the report @nicholashead
Do you have a small sample repro you can share which shows the issue?
OsirisTerje commentedon Nov 22, 2023
Just tested it here: https://github.com/nunit/nunit.issues/tree/main/Issue4554
And it works there.
nicholashead commentedon Nov 22, 2023
Sorry, I'll try to come up with a repro. Downgrading to 3.13.3 fixed it for us, in our somewhat medium/large sized solution.
OsirisTerje commentedon Nov 22, 2023
@nicholashead You can use the repro attempt I added above, and just modify that to make it "not work".
nicholashead commentedon Nov 22, 2023
I was able to identify what the cause is for us - this change - #4158 - to make the attribute not inheritable broke things. We had a global namespace class that is meant to apply a shared/inherited class's SetUpFixture logic. This works in 3.13.3 but won't in 3.14.0. Adding the
[SetUpFixture]attribute to this top level class fixes it for us. But this may trip some other folks up. Happy to close this since it appears this is an intentional change to lock down the API a little. Sorry for the noise! Thanks everyone.OsirisTerje commentedon Nov 22, 2023
Interesting, but not sure I follow the logic. You had your own setupfixtureattribute, that derived from the nunit setupfixture. Was that so that it should be easier to apply this other places, other assemblies or namespaces?
And, you solved it by marking that class as a Setupfixture instead ?
@stevenaw Comments?
nicholashead commentedon Nov 22, 2023
We have multiple test projects, and one "shared" test project (which is referenced by all the other test projects). We wanted a class in our shared project marked with
[SetUpFixture]to run for all of our test projects.Pseudo code Example of what's in the shared project:
Then in each specific project (global namespace):
This works in previous version because the attribute gets inherited in our project-specific classes. To get the latest version working again, I added
[SetUpFixture]to mySpecificProjectSetupclasses.To be fair, we just came up with this sort of structure ourselves and saw it work, but maybe there's a better way to have a "shared" setup class like we want?
OsirisTerje commentedon Nov 22, 2023
Imho, I think you have found a nice way of doing it. Nothing wrong with that, imho.
@stevenaw Should we revert?
Now, marking your derived class with the attribute will of course make it more visible that this actually is a Setupfixture, so for future maintainability it could be nice to have it there. But, apart from that, your former way looks good too.
stevenaw commentedon Nov 22, 2023
Sorry, I'd stepped away from PC after my last message and I'm not back yet. I'm hazy on the original discussion that led to that issue but the belief at the time is that there were other mechanisms preventing it from being visible on derived classes.
Sounds like reverting 3.14 is warranted but I'd like to take a closer look before we revert from 4.0. I can get a PR up tonight
nicholashead commentedon Nov 22, 2023
I'm not sure if ya'll need to revert 3.14 for this, but I defer to you! I think maybe our use case isn't a common one.
stevenaw commentedon Nov 22, 2023
Having dug a bit more, it looks like this originated based on a discussion in #3937
It seems that this inheritance -based behavior wasn't working at that time. The issue requested adding it and Charlie mentioned in there that the attribute wasn't intended to be used on a base class. There's a mention of documentation update attempts to clarify this, but at the time and even today I can't find them.
Based on the age of the issue, the version of the framework was at most 3.13.2, so I think it's likely that this started to work in a subsequent release. Though it does seem to be, quite literally, undocumented behavior.
Since it had been working in 3.x then I still think we should rollback the changes there to retain existing behavior. But since it seemed like the last discussion about it was that it shouldn't work makes me hesitant to change 4.0 unless we agree it should actually work there. In either event, we should probably update documentation and tests based on the desired direction.
@nunit/framework-team How do we want this to behave in 4.0?EDIT: I'll open another issue to track the discussion for 4.0, to which we can also associate any Relevant tests or documentation updates
stevenaw commentedon Nov 22, 2023
@nicholashead I'm just seeing your earlier comment now. We have a pretty high bar for avoiding accidentally breaking changes, so I'm happy to at least get a PR up for another team member to review and consider.
I'm glad you were able to work around it so quickly in your case 🙂
OsirisTerje commentedon Nov 24, 2023
See @CharliePoole 's comment here, which clarifies the issue. #4555 (comment)
And the conclusion is that inheritance should be allowed, just not from SetupFixture to TestFixture, which was the original intent of the discussions.
[-]SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0[/-][+]SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0/4.0.0-beta.1[/+][-]SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0/4.0.0-beta.1[/-][+]Inherited SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0/4.0.0-beta.1[/+]VulumeCode commentedon Feb 5, 2024
This change caused issue for us too. There's at least one other company out there who had the same idea as you :)