Roslyn warning for missing Skip.If()
Closed this issue · 5 comments
Would it be possible to create a Roslyn warning for missing calls to Skip.If(...)
?
Would the warning be on a [SkippableFact]
method specifically, that lacks a Skip.If
call?
I think that would generate a lot of false positives, because Skip.If just throws a specific exception type, which triggers the test to be recognized as skipped. Any code may throw this, whether in the test method or in a test helper that the test method calls. It's therefore quite common for such a test method to not directly make this call.
SkippableFact and Skip.If() belongs together. Calling one without the other should be an error.
I disagree. This is a perfectly valid test:
[SkippableFact]
public void SomeTest()
{
if (!good) throw new SkipException();
// more test;
}
But more commonly, this is also perfectly valid:
[SkippableFact]
public void SomeTest()
{
SetUpEnvironment();
// more test;
}
void SetUpEnvironment()
{
Skip.IfNot(OS.IsWindows);
}
See how in that later example, the Skip method call is not in the test method, but is nevertheless called from the test indirectly? We need the attribute to support the test helper method's ability to skip the test.
I raise this issue because a fellow developer have introduced tests that runs fine in CI, but fails on my machine. I suffer too much task switching fixing irrelevant code.
How does that relate to this issue? I can't imagine how a failure on your machine that passes in CI has to do with using the attribute without a Skip.If method call.
Now maybe I can imagine use of Skip.If in a [Fact]
method being problematic. Adding a roslyn analyzer that would flag such a method as needing an attribute change may be worthwhile. But the attribute without a visible method call within the test method itself is not an error.
If you were interested in sending a PR that added an analyzer that does this, I don't mind taking it, provided the default behavior is off. And we'd need to of course accept Skip.IfNot
as well.