Analyzer: Test class should have test method
Summary
Title: Test class should have test method
Category: Design
Description: Test class should have at least one test method, be abstract or static
Default severity: Info
From @AliveDevil
Ah, so
[TestClass] static class GlobalState { [AssemblyInitializer] …would work? If this is the case, the wording "non-abstract or static type […] should contain at least one test method" should not include "static" (or rephrase that it applies to non-abstract and non-static / non (abstract or static)), then the analyzer can be stricter for these types.
I agree with your comment @AliveDevil, the wording is not ideal and maybe we should only mention the exception cases in the rule documentation page but not on the analyzer description.
The following examples are cases where the rule should not trigger:
- Test class with no tests but some
[AssemblyInitialize]or/and[AssemblyCleanup]methods. Usually this type is static and doesn't contain anything else but some helpers but this is not hard constraint so it's probably easier to just check the presence of the attributes mentioned.
~~2. Test class with some [ClassInitialize] or [ClassCleanup] with inheritance mode. The ideal case is that this class is abstract but this is not a requirement so once again we could be looking only at the presence of the attributes.~~
Note that the rule could apply to derived types from [TestClass] because the related virtual method forces to return derived or instances of [TstMethod].
Correction for point 2, the class doesn't need to be marked as [TestClass] so we only need to avoid raising for case 1.