nunit.analyzers
nunit.analyzers copied to clipboard
Ensure Classes With TestFixtureAttribute Have at Least One Test
Description:
If a class is marked with [TestFixture], it must have at least one method marked with [Test] or [TestCase].
Example:
[TestFixture]
public class MyTests { }
To fix it:
[TestFixture]
public class MyTests
{
[Test]
public void TestMethod() { }
}
Analyzer Message:
"A test fixture class must have at least one test method."
Default Severity Level:
Error
Code Fixes:
none
This is usually true but not always, for several reasons:
-
There are other attributes that designate tests, e.g. TestCaseSource. Users can define new attributes that also designate tests.
-
A TestFixture may inherit from a base class where the tests are defined - that is the tests must exist but not necessarily be defined in the class.
@CharliePoole so I'm guessing this isn't possible to do as an analyzer, unless:
- You know which attributes constitute as "test" attributes, like
Test,TestCaseandTestCaseSource, along with a discoverable way to know what other user-created attributes designate tests - The class marked with
[TestFixture]is sealed as you know it cannot be the base class to another class.
For all practical purposes, I think that's probably true.
@CharliePoole BTW how does a user create their own test designation attributes?
By implementing certain interfaces. Is that something you are able to detect?
@CharliePoole Yes. If you give me the rules I should be able to detect that.