Skip to content

Tests won't run with an abstract base class that has a TestCaseFixtureSource #4032

Closed

Description

@thomhurst

When reporting a bug, please provide the following information to speed up triage:

  • NUnit and NUnit3TestAdapter versions
    NUnit 3.12.2 NUnit3TestAdapter 4.2.0

  • A short repro, preferably attached or pointing to a git repo or gist
    Repo Here - Can't run tests when inheriting from an abstract base class that has a TestCaseFixtureSource

  • What .net platform and version is being targeted
    .NET 6

image

Activity

  1. thomhurst commented on Jan 19, 2022

    @thomhurst
    Author

    Actually, this looks like it was caused by my TestCaseFixtureSource method being private. But NUnit didn't tell me this. Might be worth providing more information to the user.

  2. OsirisTerje commented on Jan 19, 2022

    @OsirisTerje
    Member

    @thomhurst Try to add the NUnit.Analyzers package :-) https://www.nuget.org/packages/NUnit.Analyzers/

    You should get a warning on this.

  3. OsirisTerje commented on Jan 19, 2022

    @OsirisTerje
    Member

    And I just checked it, and it doesn't. @mikkelbu : This is missing in the analyzer ?

    With private, and no warnings:
    image

    With public
    image

  4. mikkelbu commented on Jan 20, 2022

    @mikkelbu
    Member

    Currently, there is no analyzers for TestCaseFixtureSource - only for TestCaseSource. I'll create an issue for it.

    EDIT: But looking more closely then we don't have an requirement that the method is public. The problem in this case is that when we want to create an instance of MyClass then we see the TestFixtureSource, but since GetAllMyEnums is private this method is not available (I think changing it to protected would also solve the problem). Perhaps the framework should also look in the base class when we use a constructor in the base class (I'm guessing that it only examines MyClass for the method).

  5. manfred-brands commented on Jan 20, 2022

    @manfred-brands
    Member

    The TestFixtureSourceAttribute doesn't demand a public member, but the way it is implemented it won't find private members in base classes. It does use FlattenHierarchy, but that says: Private static members in inherited classes are not returned.

    @mikkelbu I have a fix for this in nunit.framework. Do you want to move this ticket or create a new one in nunit?

  6. transferred this issue fromon Jan 20, 2022
  7. manfred-brands commented on Jan 20, 2022

    @manfred-brands
    Member

    @OsirisTerje Please transfer to nunit itself not NUnit.Analyzers

  8. stevenaw commented on Feb 13, 2022

    @stevenaw
    Member

    @manfred-brands thanks for tackling this! The fix has been merged into the v3.13 branch. Would you be willing to cherry-pick the changes into main on a new PR so that they can be included in v4?

  9. added this to the 3.13.3 milestone on Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions