-
Notifications
You must be signed in to change notification settings - Fork 29
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
NUnit1025 should ignore abstract classes #696
Comments
@NinjaCross I see your problem and will try to see if I can come up with a design where it works without a warning. The reason the warning pops up is that there is no guarantee or compile error if a derived class does not implement the needed method. Can you tell me what are the .Net frameworks you are targeting. If .net 6 and later there might be more options. |
Great to know @manfred-brands, thanks !
Yes, I understand, the motivation is absolutely reasonable
.NET 6 or greater IMHO the best option would consist in being able to refer to a virtual, non-static method, but now it's not possibile, and I can understand how that would complicate things greately inside the NUnit engine. Thankyou anyway for any improvement you could implement :) |
I had hoped that the C#11 static abstract interface members would work, but if the baseclass claims to implement the interface it needs that static method. I tried One other option is to drop your inheritance and only have a (static) class with tests: public sealed class Scenario1Tests
{
private static IEnumerable<MyTestScenario> GetTestScenarios()
{
// return the tests scenarios for the "Scenario1Tests" class
return Enumerable.Empty<MyTestScenario>();
}
[TestCaseSource(nameof(GetTestScenarios))]
public void DoSomething1(MyTestScenario scenario)
{
// blah blah
}
[TestCaseSource(nameof(GetTestScenarios))]
public void DoSomething2(MyTestScenario scenario)
{
MyBaseTests.DoSomething2(scenario);
}
} If you want enforce an I looked at the nunit code and do think that it is possible to actually use instance members instead of static |
When creating complex tests, I try as much as possible to adopt OOP and general coding best practices.
An example, is creating an abstract test class, from which many concrete classes inherit and define their own extensions and specializations.
If the base abstract class contains a test method using the
ValueSource
attribute, the value ofValueSource
shouldn't be checked, or its absence shouldn't be considered an error (maybe just a warning ?), because the method could be specified into an inherited class.An example:
Is my suggestion worthy, or is there a better approach that can avoid raising NUnit1025 and implement the tests in a OOP/structured way ?
The text was updated successfully, but these errors were encountered: