|
2 | 2 |
|
3 | 3 | namespace TUnit.Core; |
4 | 4 |
|
| 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> |
5 | 46 | public class ParallelGroupAttribute(string group) : TUnitAttribute, ITestDiscoveryEventReceiver |
6 | 47 | { |
7 | | - int IEventReceiver.Order => 0; |
8 | | - |
| 48 | + /// <inheritdoc /> |
9 | 49 | public int Order { get; set; } |
10 | 50 |
|
| 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"/> |
11 | 78 | public string Group { get; } = group; |
12 | 79 |
|
| 80 | + /// <inheritdoc /> |
13 | 81 | public void OnTestDiscovery(DiscoveredTestContext discoveredTestContext) |
14 | 82 | { |
15 | 83 | discoveredTestContext.SetParallelConstraint(new ParallelGroupConstraint(Group, Order)); |
|
0 commit comments