From c1f92c0babf6c1a8fa96e3fe4fe89f6918eb4ca3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 28 May 2026 17:59:25 +0000 Subject: [PATCH 1/6] Initial plan From e7323711fb2a2ff17458ef5abf32a26faaf864d4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 28 May 2026 18:01:42 +0000 Subject: [PATCH 2/6] docs: document MaxTime's WarningTime warning threshold parameter (NUnit 5) --- .../nunit/writing-tests/attributes/maxtime.md | 11 ++++++++++ .../Attributes/MaxTimeAttributeExamples.cs | 20 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/docs/articles/nunit/writing-tests/attributes/maxtime.md b/docs/articles/nunit/writing-tests/attributes/maxtime.md index 706dd355b..58d14c837 100644 --- a/docs/articles/nunit/writing-tests/attributes/maxtime.md +++ b/docs/articles/nunit/writing-tests/attributes/maxtime.md @@ -18,6 +18,12 @@ MaxTimeAttribute(int milliseconds) |-----------|------|-------------| | `milliseconds` | `int` | The maximum elapsed time in milliseconds. If the test exceeds this time, it fails. | +## Named Parameters + +| Parameter | Type | Description | +|-----------|------|-------------| +| `WarningTime` | `int` | An optional warning threshold in milliseconds. If the test takes longer than this time but less than the maximum time, the test result is set to `Warning`. A value of `0` (the default) disables the warning threshold. (**NUnit 5**) | + ## Applies To | Test Methods | Test Fixtures (Classes) | Assembly | @@ -34,6 +40,10 @@ MaxTimeAttribute(int milliseconds) [!code-csharp[MaxTimeVsAssertions](~/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs#MaxTimeVsAssertions)] +### Warning Threshold + +[!code-csharp[MaxTimeWarningThreshold](~/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs#MaxTimeWarningThreshold)] + ## Notes 1. Any assertion failures take precedence over the elapsed time check. If a test both fails an assertion and exceeds the time limit, the assertion failure is reported. @@ -41,6 +51,7 @@ MaxTimeAttribute(int milliseconds) 3. For tests that need to be cancelled when they exceed a time limit, use [CancelAfter Attribute](xref:attribute-cancelafter) instead. 4. The timing includes the test method execution only, not `SetUp` or `TearDown` methods. 5. The [Timeout Attribute](xref:attribute-timeout) uses `Thread.Abort` and only works on .NET Framework. +6. The optional `WarningTime` named parameter (added in **NUnit 5**) sets a soft threshold: if the test exceeds it but still passes within the maximum time, the result is `Warning` rather than `Failure`. ## See Also diff --git a/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs b/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs index 35b94111c..78902dd5c 100644 --- a/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs +++ b/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs @@ -50,5 +50,25 @@ public void AssertionFailuresTakePrecedence() } } #endregion + + #region MaxTimeWarningThreshold + [TestFixture] + public class MaxTimeWarningThresholdTests + { + [Test] + [MaxTime(1000, WarningTime = 200)] + public void OperationWithWarningThreshold() + { + // Test passes if it completes within 1000ms. + // If it takes more than 200ms but less than 1000ms, the result is Warning. + PerformOperation(); + } + + private void PerformOperation() + { + // Simulate an operation + } + } + #endregion } } From 4ffb41c466029acde87a990691d84d36e82fee2b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 28 May 2026 18:48:20 +0000 Subject: [PATCH 3/6] docs: address review feedback - simplify warning example and fix NUnit 5+ label --- docs/articles/nunit/writing-tests/attributes/maxtime.md | 4 ++-- .../Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/articles/nunit/writing-tests/attributes/maxtime.md b/docs/articles/nunit/writing-tests/attributes/maxtime.md index 58d14c837..2544f275e 100644 --- a/docs/articles/nunit/writing-tests/attributes/maxtime.md +++ b/docs/articles/nunit/writing-tests/attributes/maxtime.md @@ -22,7 +22,7 @@ MaxTimeAttribute(int milliseconds) | Parameter | Type | Description | |-----------|------|-------------| -| `WarningTime` | `int` | An optional warning threshold in milliseconds. If the test takes longer than this time but less than the maximum time, the test result is set to `Warning`. A value of `0` (the default) disables the warning threshold. (**NUnit 5**) | +| `WarningTime` | `int` | An optional warning threshold in milliseconds. If the test takes longer than this time but less than the maximum time, the test result is set to `Warning`. A value of `0` (the default) disables the warning threshold. (**NUnit 5+**) | ## Applies To @@ -51,7 +51,7 @@ MaxTimeAttribute(int milliseconds) 3. For tests that need to be cancelled when they exceed a time limit, use [CancelAfter Attribute](xref:attribute-cancelafter) instead. 4. The timing includes the test method execution only, not `SetUp` or `TearDown` methods. 5. The [Timeout Attribute](xref:attribute-timeout) uses `Thread.Abort` and only works on .NET Framework. -6. The optional `WarningTime` named parameter (added in **NUnit 5**) sets a soft threshold: if the test exceeds it but still passes within the maximum time, the result is `Warning` rather than `Failure`. +6. The optional `WarningTime` named parameter (added in **NUnit 5+**) sets a soft threshold: if the test exceeds it but still passes within the maximum time, the result is `Warning` rather than `Failure`. ## See Also diff --git a/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs b/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs index 78902dd5c..8c9e6a185 100644 --- a/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs +++ b/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs @@ -61,12 +61,8 @@ public void OperationWithWarningThreshold() { // Test passes if it completes within 1000ms. // If it takes more than 200ms but less than 1000ms, the result is Warning. - PerformOperation(); - } - - private void PerformOperation() - { - // Simulate an operation + int delay = Random.Shared.Next(100, 1500); + Thread.Sleep(delay); } } #endregion From d19a6df7eee08754e930f95cce266fa53869d2c1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 28 May 2026 19:10:12 +0000 Subject: [PATCH 4/6] fix: update NUnit package to 5.0.0-alpha.100.9 to fix build --- docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj b/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj index e51bb029b..bf290b9ea 100644 --- a/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj +++ b/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj @@ -10,7 +10,7 @@ - + all From 284d410f46ac62c7cd05e0044231fecba0debd07 Mon Sep 17 00:00:00 2001 From: Steven Weerdenburg Date: Thu, 28 May 2026 15:30:20 -0400 Subject: [PATCH 5/6] Downgrade NUnit package version Downgrade NUnit package version from 5.0.0-alpha.100.9 to 5.0.0-alpha.100.7. --- docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj b/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj index bf290b9ea..dddd7796f 100644 --- a/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj +++ b/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj @@ -10,7 +10,7 @@ - + all From 43acaa931183b2aa4a9b8f45f5854ec988a0dd53 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 28 May 2026 23:58:18 +0000 Subject: [PATCH 6/6] fix: replace random sleep with constant 201ms in warning threshold example --- .../Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs b/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs index 8c9e6a185..5b7211eb9 100644 --- a/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs +++ b/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs @@ -61,8 +61,7 @@ public void OperationWithWarningThreshold() { // Test passes if it completes within 1000ms. // If it takes more than 200ms but less than 1000ms, the result is Warning. - int delay = Random.Shared.Next(100, 1500); - Thread.Sleep(delay); + Thread.Sleep(201); } } #endregion