Skip to content

Commit 4719575

Browse files
authored
Skip methods in test-merging if they use the named argument 'Skip' for the Fact attributes (#85495)
* Skip methods in test-merging if they use the named argument 'Skip' * Use ActiveIssueAttribute instead of FactAttribute with Skip. Add documentation about FactAttribute and Skip.
1 parent 97e9be9 commit 4719575

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

docs/workflow/testing/libraries/filtering-tests.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,15 @@ A common usage in the libraries tests is the following:
337337
```
338338
339339
This is put on test classes to indicate that none of the tests in that class (which as usual run serially with respect to each other) may run concurrently with tests in another class. This is used for tests that use a lot of disk space or memory, or dominate all the cores, such that they are likely to disrupt any tests that run concurrently.
340+
341+
## FactAttribute and `Skip`
342+
343+
Another way to disable the test entirely is to use the `Skip` named argument that is used on the `FactAttribute`.
344+
345+
Example:
346+
```cs
347+
[Fact(Skip = "<reason for skipping>")]
348+
```
349+
350+
If the reason for skipping is a link to an issue, it is recommended to use the `ActiveIssueAttribute` instead.
351+
Otherwise, `Skip` allows for a more descriptive reason.

src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,21 +464,35 @@ private static IEnumerable<ITestInfo> GetTestMethodInfosForMethod(IMethodSymbol
464464
List<AttributeData> filterAttributes = new();
465465
foreach (var attr in method.GetAttributesOnSelfAndContainingSymbols())
466466
{
467+
var hasSkip = attr.NamedArguments.Any(x => x.Key == "Skip");
468+
467469
switch (attr.AttributeClass?.ToDisplayString())
468470
{
469471
case "Xunit.ConditionalFactAttribute":
470-
filterAttributes.Add(attr);
471-
factAttribute = true;
472+
if (!hasSkip)
473+
{
474+
filterAttributes.Add(attr);
475+
factAttribute = true;
476+
}
472477
break;
473478
case "Xunit.FactAttribute":
474-
factAttribute = true;
479+
if (!hasSkip)
480+
{
481+
factAttribute = true;
482+
}
475483
break;
476484
case "Xunit.ConditionalTheoryAttribute":
477-
filterAttributes.Add(attr);
478-
theoryAttribute = true;
485+
if (!hasSkip)
486+
{
487+
filterAttributes.Add(attr);
488+
theoryAttribute = true;
489+
}
479490
break;
480491
case "Xunit.TheoryAttribute":
481-
theoryAttribute = true;
492+
if (!hasSkip)
493+
{
494+
theoryAttribute = true;
495+
}
482496
break;
483497
case "Xunit.ConditionalClassAttribute":
484498
case "Xunit.SkipOnPlatformAttribute":

src/tests/JIT/Regression/JitBlue/Runtime_84693/Runtime_84693.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static int M8(byte arg0)
2828
}
2929
}
3030

31-
[Fact(Skip = "https://github.com/dotnet/runtime/issues/85081")]
31+
[ActiveIssue("https://github.com/dotnet/runtime/issues/85081")]
3232
public static int TestEntryPoint() {
3333
var result = Test.Program.M8(1);
3434
if (result != 255)

0 commit comments

Comments
 (0)