22
33namespace TUnit . Core ;
44
5+ /// <summary>
6+ /// Specifies that a test method, test class, or assembly should be skipped during test execution.
7+ /// </summary>
8+ /// <remarks>
9+ /// When applied to a test method, class, or assembly, the SkipAttribute prevents the test(s) from being executed
10+ /// and marks them as skipped with the provided reason.
11+ ///
12+ /// Skip can be applied at the method, class, or assembly level.
13+ /// When applied at a class level, all test methods in the class will be skipped.
14+ /// When applied at the assembly level, it affects all tests in the assembly.
15+ /// </remarks>
16+ /// <example>
17+ /// <code>
18+ /// [Test]
19+ /// [Skip("Not implemented yet")]
20+ /// public void TestThatIsNotReady()
21+ /// {
22+ /// // This test will be skipped with the reason "Not implemented yet"
23+ /// }
24+ ///
25+ /// // Example of a custom skip attribute with conditional logic
26+ /// public class SkipOnLinuxAttribute : SkipAttribute
27+ /// {
28+ /// public SkipOnLinuxAttribute() : base("Test not supported on Linux")
29+ /// {
30+ /// }
31+ ///
32+ /// public override Task<bool> ShouldSkip(TestRegisteredContext context)
33+ /// {
34+ /// return Task.FromResult(System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
35+ /// }
36+ /// }
37+ /// </code>
38+ /// </example>
539[ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Class | AttributeTargets . Assembly , AllowMultiple = true ) ]
640public class SkipAttribute : Attribute , ITestRegisteredEventReceiver
741{
@@ -26,5 +60,19 @@ public async ValueTask OnTestRegistered(TestRegisteredContext context)
2660 }
2761 }
2862
63+ /// <summary>
64+ /// Determines whether a test should be skipped.
65+ /// </summary>
66+ /// <param name="context">The test context containing information about the test being registered.</param>
67+ /// <returns>
68+ /// A task that represents the asynchronous operation.
69+ /// The task result is true if the test should be skipped; otherwise, false.
70+ /// </returns>
71+ /// <remarks>
72+ /// Can be overridden in derived classes to implement conditional skip logic
73+ /// based on specific conditions or criteria.
74+ ///
75+ /// The default implementation always returns true, meaning the test will always be skipped.
76+ /// </remarks>
2977 public virtual Task < bool > ShouldSkip ( TestRegisteredContext context ) => Task . FromResult ( true ) ;
3078}
0 commit comments