-
Notifications
You must be signed in to change notification settings - Fork 253
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
MSTEST0012 and MSTEST0016 contradict each other. One wants the containing class to be static, the other wants a non-static class. #3818
Comments
Hi @baumheld, Thanks for ticket! There are indeed multiple things that are wrong on our side. The documentation for MSTEST0012 and MSTEST0013 are incorrect (it's valid to have The documentation for MSTEST0016 should be improved to say that the class should be either There is nothing mandatory but I would probably recommend to have a different class for the Assuming this base class is really meant to have no tests, I would recommend to mark the class has |
Indeed, adding public abstract class BaseClass
{
public TestContext TestContext { get; set; } = null!;
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext) // => MSTEST0012 Warning
{
}
[AssemblyCleanup]
public static void AssemblyCleanup() // => MSTEST0013 Warning
{
}
} |
These warnings are actually correct. You should keep the Either you should have [TestClass]
public abstract class BaseClass
{
public TestContext TestContext { get; set; } = null!;
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext)
{
}
[AssemblyCleanup]
public static void AssemblyCleanup()
{
}
[TestInitialize]
public void TestInitialize()
{
}
[TestCleanup]
public void TestCleanup()
{
}
} or something like [TestClass]
public static class GlobalHooks
{
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext)
{
}
[AssemblyCleanup]
public static void AssemblyCleanup()
{
}
}
public abstract class BaseClass
{
public TestContext TestContext { get; set; } = null!;
[TestInitialize]
public void TestInitialize()
{
}
[TestCleanup]
public void TestCleanup()
{
}
} |
Describe the bug
MSTEST0012 and MSTEST0016 contradict each other. One wants the containing class to be static, the other wants a non-static class.
MSTEST0012
MSTEST0016
Can I satisfy both rules or is this a bug?
Steps To Reproduce
The methods
AssemblyInitialize
andAssemblyCleanup
are within a base class which other normal test classes derive from. Naturally, there are no tests within that base class. I don't know why MSTEST0012 wants me to mark a base class with[TestClass]
, but I'm okay with that.Expected behavior
No analyzer suggestions or warnings
Actual behavior
Code Analyzer suggestion MSTEST0016 is displayed
Additional context
This also affects MSTEST0013 (AssemblyCleanup).
The text was updated successfully, but these errors were encountered: