Skip to content

Commit 6be9e71

Browse files
authored
docs: Further XML Summaries for TUnit.Core/Attributes (#2509)
1 parent 00df8bb commit 6be9e71

File tree

4 files changed

+145
-2
lines changed

4 files changed

+145
-2
lines changed

TUnit.Core/Attributes/ParallelGroupAttribute.cs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,82 @@
22

33
namespace TUnit.Core;
44

5+
6+
/// <summary>
7+
/// Specifies that a test method, class, or assembly belongs to a parallel execution group.
8+
/// </summary>
9+
/// <remarks>
10+
/// <para>
11+
/// Tests within the same parallel group will run in parallel with each other but not with tests from other groups.
12+
/// This attribute helps to organize test execution when you want to control how certain tests run in relation to others.
13+
/// </para>
14+
/// <para>
15+
/// The test engine processes parallel groups sequentially based on their <see cref="Order"/> property, but tests
16+
/// within the same group execute in parallel with each other. This is useful for organizing tests that should
17+
/// run concurrently but in separate batches from other test groups.
18+
/// </para>
19+
/// <para>
20+
/// This attribute implements <see cref="ITestDiscoveryEventReceiver"/> to register a <see cref="ParallelGroupConstraint"/>
21+
/// with the test discovery system, which the test execution engine uses to organize and schedule test execution.
22+
/// </para>
23+
/// <para>
24+
/// Example usage:
25+
/// <code>
26+
/// [Test, ParallelGroup("DatabaseTests")]
27+
/// public async Task DatabaseTest1()
28+
/// {
29+
/// // This test will run in parallel with other tests in the "DatabaseTests" group
30+
/// }
31+
///
32+
/// [Test, ParallelGroup("DatabaseTests")]
33+
/// public async Task DatabaseTest2()
34+
/// {
35+
/// // This will run in parallel with DatabaseTest1
36+
/// }
37+
///
38+
/// [Test, ParallelGroup("UITests", Order = 1)]
39+
/// public async Task UITest1()
40+
/// {
41+
/// // This test belongs to a different
42+
/// }
43+
/// </code>
44+
/// </para>
45+
/// </remarks>
546
public class ParallelGroupAttribute(string group) : TUnitAttribute, ITestDiscoveryEventReceiver
647
{
7-
int IEventReceiver.Order => 0;
8-
48+
/// <inheritdoc />
949
public int Order { get; set; }
1050

51+
/// <summary>
52+
/// Gets the name of the parallel group to which the test belongs.
53+
/// </summary>
54+
/// <remarks>
55+
/// <para>
56+
/// The group name is used to identify which tests should be executed in parallel with each other.
57+
/// Tests decorated with <see cref="ParallelGroupAttribute"/> that have the same <see cref="Group"/> value
58+
/// will be grouped together and executed concurrently, but isolated from tests in other groups.
59+
/// </para>
60+
/// <para>
61+
/// Group names are case-sensitive string identifiers that should be chosen to represent a logical
62+
/// set of tests that can safely run in parallel with each other. For example, "DatabaseTests",
63+
/// "NetworkTests", or "UITests".
64+
/// </para>
65+
/// <para>
66+
/// During test execution, the test engine organizes tests into groups based on this property, and
67+
/// ensures that tests from different groups are not executed simultaneously, helping to manage
68+
/// resource contention and test isolation.
69+
/// </para>
70+
/// <para>
71+
/// This property is set via the constructor parameter and cannot be changed after the attribute
72+
/// is instantiated.
73+
/// </para>
74+
/// </remarks>
75+
/// <seealso cref="ParallelGroupConstraint"/>
76+
/// <seealso cref="IParallelConstraint"/>
77+
/// <seealso cref="NotInParallelAttribute"/>
1178
public string Group { get; } = group;
1279

80+
/// <inheritdoc />
1381
public void OnTestDiscovery(DiscoveredTestContext discoveredTestContext)
1482
{
1583
discoveredTestContext.SetParallelConstraint(new ParallelGroupConstraint(Group, Order));

TUnit.Core/Attributes/ParallelLimiterAttribute.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,61 @@
22

33
namespace TUnit.Core;
44

5+
/// <summary>
6+
/// Limits the number of tests that can run in parallel for a test assembly, class, or method.
7+
/// </summary>
8+
/// <typeparam name="TParallelLimit">
9+
/// The type that implements <see cref="IParallelLimit"/> and defines the maximum number
10+
/// of tests that can execute concurrently.
11+
/// </typeparam>
12+
/// <remarks>
13+
/// <para>
14+
/// This attribute controls the degree of parallelism for test execution. When applied to a test assembly,
15+
/// class, or method, it limits how many tests from that scope can run simultaneously.
16+
/// </para>
17+
/// <para>
18+
/// The parallelism limit is defined by the <see cref="IParallelLimit.Limit"/> property of the
19+
/// <typeparamref name="TParallelLimit"/> instance. This value is used to create a semaphore that
20+
/// controls concurrent test execution.
21+
/// </para>
22+
/// <para>
23+
/// Common implementations include:
24+
/// <list type="bullet">
25+
/// <item><description><c>DefaultParallelLimit</c> - Uses <see cref="Environment.ProcessorCount"/> as the limit</description></item>
26+
/// <item><description>Custom implementations with fixed limits (e.g., <c>ParallelLimit3</c> with a limit of 3)</description></item>
27+
/// </list>
28+
/// </para>
29+
/// <para>
30+
/// Example usage:
31+
/// <code>
32+
/// // Apply to an assembly to limit all tests
33+
/// [assembly: ParallelLimiter&lt;DefaultParallelLimit&gt;]
34+
///
35+
/// // Apply to a class to limit tests in that class
36+
/// [ParallelLimiter&lt;ParallelLimit3&gt;]
37+
/// public class MyTestClass
38+
/// {
39+
/// // Tests in this class will run with a maximum of 3 in parallel
40+
/// }
41+
///
42+
/// // Apply to a specific test method
43+
/// [Test]
44+
/// [ParallelLimiter&lt;ParallelLimit1&gt;]
45+
/// public void MyTest()
46+
/// {
47+
/// // This test will run exclusively (limit of 1)
48+
/// }
49+
/// </code>
50+
/// </para>
51+
/// </remarks>
552
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
653
public sealed class ParallelLimiterAttribute<TParallelLimit> : TUnitAttribute, ITestRegisteredEventReceiver
754
where TParallelLimit : IParallelLimit, new()
855
{
56+
/// <inheritdoc />
957
public int Order => 0;
1058

59+
/// <inheritdoc />
1160
public ValueTask OnTestRegistered(TestRegisteredContext testRegisteredContext)
1261
{
1362
testRegisteredContext.SetParallelLimiter(new TParallelLimit());
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
namespace TUnit.Core;
22

3+
/// <summary>
4+
/// Marks a class as inheriting test methods from its base classes.
5+
/// </summary>
6+
/// <remarks>
7+
/// This attribute indicates to the TUnit test runner that test methods defined in base classes
8+
/// should be considered part of the derived class's test suite.
9+
/// </remarks>
310
[AttributeUsage(AttributeTargets.Class)]
411
public sealed class InheritsTestsAttribute : TUnitAttribute;

TUnit.Core/Attributes/Tests/TestAttribute.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
namespace TUnit.Core;
44

5+
/// <summary>
6+
/// Marks a method as a test method in the TUnit testing framework.
7+
/// </summary>
8+
/// <remarks>
9+
/// Methods marked with this attribute will be discovered and executed as tests during test runs.
10+
/// The attribute automatically captures the file path and line number where the test is defined.
11+
/// </remarks>
12+
/// <example>
13+
/// <code>
14+
/// public class ExampleTests
15+
/// {
16+
/// [Test]
17+
/// public void ExampleTest()
18+
/// {
19+
/// // Test code here
20+
/// }
21+
/// }
22+
/// </code>
23+
/// </example>
524
[AttributeUsage(AttributeTargets.Method)]
625
public sealed class TestAttribute(
726
[CallerFilePath] string file = "",

0 commit comments

Comments
 (0)