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
Tests won't run with an abstract base class that has a TestCaseFixtureSource #4032
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
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.
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).
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?
@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?
Activity
thomhurst commentedon Jan 19, 2022
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.
OsirisTerje commentedon Jan 19, 2022
@thomhurst Try to add the NUnit.Analyzers package :-) https://www.nuget.org/packages/NUnit.Analyzers/
You should get a warning on this.
OsirisTerje commentedon Jan 19, 2022
And I just checked it, and it doesn't. @mikkelbu : This is missing in the analyzer ?
With private, and no warnings:

With public

mikkelbu commentedon Jan 20, 2022
Currently, there is no analyzers for
TestCaseFixtureSource- only forTestCaseSource. 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
MyClassthen we see theTestFixtureSource, but sinceGetAllMyEnumsis 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 examinesMyClassfor the method).manfred-brands commentedon Jan 20, 2022
The
TestFixtureSourceAttributedoesn't demand apublicmember, but the way it is implemented it won't findprivatemembers in base classes. It does useFlattenHierarchy, 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?
manfred-brands commentedon Jan 20, 2022
@OsirisTerje Please transfer to nunit itself not NUnit.Analyzers
stevenaw commentedon Feb 13, 2022
@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?