Skip to content

Inherited SetUpFixture has stopped working going from NUnit 3.13.3 to 3.14.0/4.0.0-beta.1 #4554

Closed

Description

@nicholashead

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.

Activity

  1. stevenaw commented on Nov 22, 2023

    @stevenaw
    Member

    Thanks for the report @nicholashead
    Do you have a small sample repro you can share which shows the issue?

  2. OsirisTerje commented on Nov 22, 2023

    @OsirisTerje
    Member

    Just tested it here: https://github.com/nunit/nunit.issues/tree/main/Issue4554
    And it works there.

  3. nicholashead commented on Nov 22, 2023

    @nicholashead
    Author

    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.

  4. added
    awaiting:reproA small repro is needed. Upload here or add PR to nunit.issues
    on Nov 22, 2023
  5. OsirisTerje commented on Nov 22, 2023

    @OsirisTerje
    Member

    @nicholashead You can use the repro attempt I added above, and just modify that to make it "not work".

  6. nicholashead commented on Nov 22, 2023

    @nicholashead
    Author

    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.

  7. OsirisTerje commented on Nov 22, 2023

    @OsirisTerje
    Member

    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?

  8. added and removed
    awaiting:reproA small repro is needed. Upload here or add PR to nunit.issues
    on Nov 22, 2023
  9. nicholashead commented on Nov 22, 2023

    @nicholashead
    Author

    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?

    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:

    namespace SharedTestLogic {
        [SetUpFixture]
        public class SharedSetup() {
            [OneTimeSetUp]
            public void Setup()
            {
                DoSomething();
            } 
        }
    }

    Then in each specific project (global namespace):

    public class SpecificProjectSetup : SharedTestLogic.SharedSetup { }

    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?

  10. OsirisTerje commented on Nov 22, 2023

    @OsirisTerje
    Member

    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.

  11. stevenaw commented on Nov 22, 2023

    @stevenaw
    Member

    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

  12. nicholashead commented on Nov 22, 2023

    @nicholashead
    Author

    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.

  13. stevenaw commented on Nov 22, 2023

    @stevenaw
    Member

    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

  14. stevenaw commented on Nov 22, 2023

    @stevenaw
    Member

    @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 🙂

  15. OsirisTerje commented on Nov 24, 2023

    @OsirisTerje
    Member

    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.

  16. added this to the 4.0 milestone on Nov 24, 2023
  17. 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
  18. 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
  19. VulumeCode commented on Feb 5, 2024

    @VulumeCode

    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.

    This change caused issue for us too. There's at least one other company out there who had the same idea as you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions