From 86a819a848959aa204ed0a9f980ac6e2b4f30a8c Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sat, 21 Feb 2026 19:18:15 +0100 Subject: [PATCH 1/9] updated Timeout attribute --- .../nunit/writing-tests/attributes/timeout.md | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/attributes/timeout.md b/docs/articles/nunit/writing-tests/attributes/timeout.md index 6df9d6ee9..faa751627 100644 --- a/docs/articles/nunit/writing-tests/attributes/timeout.md +++ b/docs/articles/nunit/writing-tests/attributes/timeout.md @@ -1,7 +1,25 @@ # Timeout > [!NOTE] -> From version 3.12 this is also available in the .NET Standard 2.0 builds of the framework. +> The Timeout attribute does not work from .net 5 and upwards. +> From version 4.5 usage of Timeout attribute where the target framework is .net5 or higher is reported as a failure. + +## Alternatives to the Timeout attribute for .net 5 and above + +If you want to cancel the Test in the same manner, use the [CancelAfter Attribute](./cancelafter.md). +It is cooperative cancelling, so your test needs to handle the CancellationToken. + +If you just want to be informed of tests that have run over an expected time, use the [MaxTime Attribute](./maxtime.md). + +If you want to cancel the whole test run use the `dotnet test --blame-hang-timeout `. +See [dotnet test docs](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test-vstest). + +### Reason + +The Timeout attribute use the Thread.Abort to kill tests. The Thread.Abort was removed in .net 5, and replaced with +cooperative cancellation. + +## For projects that target .Net Framework only Normally, NUnit simply runs tests and waits for them to terminate -- the test is allowed to run indefinitely. For certain kinds of tests, however, it may be desirable to specify a timeout value. From bb2de791f505cb611e5f00fa7ee3e53d1f0bf713 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sat, 21 Feb 2026 19:28:29 +0100 Subject: [PATCH 2/9] updated maxtime --- docs/articles/nunit/writing-tests/attributes/maxtime.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/attributes/maxtime.md b/docs/articles/nunit/writing-tests/attributes/maxtime.md index c51ebf313..04bedbf48 100644 --- a/docs/articles/nunit/writing-tests/attributes/maxtime.md +++ b/docs/articles/nunit/writing-tests/attributes/maxtime.md @@ -21,4 +21,5 @@ public void TimedTest() 2. This attribute does not cancel the test if the time is exceeded. It merely waits for the test to complete and then compares the elapsed time to the specified maximum. If you want to - cancel long-running tests, see [Timeout Attribute](timeout.md). + cancel long-running tests, see [CancelAfter Attribute](cancelafter.md). + The [Timeout Attribute](timeout.md) only works for .net framework and will give a test error if used for .net. From d87fd4c84ff7af75b6619e2aaf4b2733857a16e6 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sat, 21 Feb 2026 19:33:22 +0100 Subject: [PATCH 3/9] updated maxtime --- cSpell.json | 1 + docs/articles/nunit/writing-tests/attributes/maxtime.md | 5 +++++ docs/articles/nunit/writing-tests/attributes/timeout.md | 1 + 3 files changed, 7 insertions(+) diff --git a/cSpell.json b/cSpell.json index 41894795c..c21ba1af5 100644 --- a/cSpell.json +++ b/cSpell.json @@ -157,6 +157,7 @@ "Maddock", "Frans", "Bouma", + "TIMESPAN", "yowko" ], "patterns": [ diff --git a/docs/articles/nunit/writing-tests/attributes/maxtime.md b/docs/articles/nunit/writing-tests/attributes/maxtime.md index 04bedbf48..f997939dd 100644 --- a/docs/articles/nunit/writing-tests/attributes/maxtime.md +++ b/docs/articles/nunit/writing-tests/attributes/maxtime.md @@ -23,3 +23,8 @@ public void TimedTest() compares the elapsed time to the specified maximum. If you want to cancel long-running tests, see [CancelAfter Attribute](cancelafter.md). The [Timeout Attribute](timeout.md) only works for .net framework and will give a test error if used for .net. + +## See Also + +* [CancelAfter Attribute](./cancelafter.md) +* [Timeout Attribute](timeout.md) diff --git a/docs/articles/nunit/writing-tests/attributes/timeout.md b/docs/articles/nunit/writing-tests/attributes/timeout.md index faa751627..ffb44634e 100644 --- a/docs/articles/nunit/writing-tests/attributes/timeout.md +++ b/docs/articles/nunit/writing-tests/attributes/timeout.md @@ -12,6 +12,7 @@ It is cooperative cancelling, so your test needs to handle the CancellationToken If you just want to be informed of tests that have run over an expected time, use the [MaxTime Attribute](./maxtime.md). If you want to cancel the whole test run use the `dotnet test --blame-hang-timeout `. +Any test that use more than the TIMESPAN will abort the run. See [dotnet test docs](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test-vstest). ### Reason From e4f83cf46b81e5994830943424e44002cc9e6134 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sat, 21 Feb 2026 20:11:38 +0100 Subject: [PATCH 4/9] Update docs/articles/nunit/writing-tests/attributes/maxtime.md Co-authored-by: Steven Weerdenburg --- docs/articles/nunit/writing-tests/attributes/maxtime.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/attributes/maxtime.md b/docs/articles/nunit/writing-tests/attributes/maxtime.md index f997939dd..8200778e8 100644 --- a/docs/articles/nunit/writing-tests/attributes/maxtime.md +++ b/docs/articles/nunit/writing-tests/attributes/maxtime.md @@ -22,7 +22,7 @@ public void TimedTest() is exceeded. It merely waits for the test to complete and then compares the elapsed time to the specified maximum. If you want to cancel long-running tests, see [CancelAfter Attribute](cancelafter.md). - The [Timeout Attribute](timeout.md) only works for .net framework and will give a test error if used for .net. + The [Timeout Attribute](timeout.md) only works for .NET Framework and will give a test error if used for .NET. ## See Also From 174f9b00c2f1a3cd62175b414a32e966f2dad911 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sat, 21 Feb 2026 20:11:52 +0100 Subject: [PATCH 5/9] Update docs/articles/nunit/writing-tests/attributes/timeout.md Co-authored-by: Steven Weerdenburg --- docs/articles/nunit/writing-tests/attributes/timeout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/attributes/timeout.md b/docs/articles/nunit/writing-tests/attributes/timeout.md index ffb44634e..c722eb4be 100644 --- a/docs/articles/nunit/writing-tests/attributes/timeout.md +++ b/docs/articles/nunit/writing-tests/attributes/timeout.md @@ -1,7 +1,7 @@ # Timeout > [!NOTE] -> The Timeout attribute does not work from .net 5 and upwards. +> The Timeout attribute does not work from .NET 5 and upwards due to limitations in the runtime. > From version 4.5 usage of Timeout attribute where the target framework is .net5 or higher is reported as a failure. ## Alternatives to the Timeout attribute for .net 5 and above From 400055e54906656e8860acf43ccdabf25fa576ea Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sat, 21 Feb 2026 20:12:12 +0100 Subject: [PATCH 6/9] Update docs/articles/nunit/writing-tests/attributes/timeout.md Co-authored-by: Steven Weerdenburg --- docs/articles/nunit/writing-tests/attributes/timeout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/attributes/timeout.md b/docs/articles/nunit/writing-tests/attributes/timeout.md index c722eb4be..8d5fff6d1 100644 --- a/docs/articles/nunit/writing-tests/attributes/timeout.md +++ b/docs/articles/nunit/writing-tests/attributes/timeout.md @@ -2,7 +2,7 @@ > [!NOTE] > The Timeout attribute does not work from .NET 5 and upwards due to limitations in the runtime. -> From version 4.5 usage of Timeout attribute where the target framework is .net5 or higher is reported as a failure. +> Beginning in NUnit version 4.5, usage of Timeout attribute on .NET 5 or higher is reported as a failure. ## Alternatives to the Timeout attribute for .net 5 and above From ff5a99d75f872cfc775621a413d63dbf15b32e55 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sat, 21 Feb 2026 20:12:29 +0100 Subject: [PATCH 7/9] Update docs/articles/nunit/writing-tests/attributes/timeout.md Co-authored-by: Steven Weerdenburg --- docs/articles/nunit/writing-tests/attributes/timeout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/attributes/timeout.md b/docs/articles/nunit/writing-tests/attributes/timeout.md index 8d5fff6d1..588c57721 100644 --- a/docs/articles/nunit/writing-tests/attributes/timeout.md +++ b/docs/articles/nunit/writing-tests/attributes/timeout.md @@ -17,7 +17,7 @@ See [dotnet test docs](https://learn.microsoft.com/en-us/dotnet/core/tools/dotne ### Reason -The Timeout attribute use the Thread.Abort to kill tests. The Thread.Abort was removed in .net 5, and replaced with +The Timeout attribute use the `Thread.Abort()` method to kill tests. `Thread.Abort()` was removed in .NET 5 and replaced with cooperative cancellation. ## For projects that target .Net Framework only From 7157b69145d63f8da4dfefbf11337e8762710a18 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Sat, 21 Feb 2026 19:29:17 -0500 Subject: [PATCH 8/9] Update docs/articles/nunit/writing-tests/attributes/timeout.md --- docs/articles/nunit/writing-tests/attributes/timeout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/attributes/timeout.md b/docs/articles/nunit/writing-tests/attributes/timeout.md index 588c57721..9a86237eb 100644 --- a/docs/articles/nunit/writing-tests/attributes/timeout.md +++ b/docs/articles/nunit/writing-tests/attributes/timeout.md @@ -17,7 +17,7 @@ See [dotnet test docs](https://learn.microsoft.com/en-us/dotnet/core/tools/dotne ### Reason -The Timeout attribute use the `Thread.Abort()` method to kill tests. `Thread.Abort()` was removed in .NET 5 and replaced with +The Timeout attribute uses the `Thread.Abort()` method to kill tests. `Thread.Abort()` was removed in .NET 5 and replaced with cooperative cancellation. ## For projects that target .Net Framework only From 5d8892612f5045a360e82fb25fcaad68458572c2 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Sat, 21 Feb 2026 19:29:25 -0500 Subject: [PATCH 9/9] Update docs/articles/nunit/writing-tests/attributes/timeout.md --- docs/articles/nunit/writing-tests/attributes/timeout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/attributes/timeout.md b/docs/articles/nunit/writing-tests/attributes/timeout.md index 9a86237eb..232a158b7 100644 --- a/docs/articles/nunit/writing-tests/attributes/timeout.md +++ b/docs/articles/nunit/writing-tests/attributes/timeout.md @@ -20,7 +20,7 @@ See [dotnet test docs](https://learn.microsoft.com/en-us/dotnet/core/tools/dotne The Timeout attribute uses the `Thread.Abort()` method to kill tests. `Thread.Abort()` was removed in .NET 5 and replaced with cooperative cancellation. -## For projects that target .Net Framework only +## For projects that target .NET Framework only Normally, NUnit simply runs tests and waits for them to terminate -- the test is allowed to run indefinitely. For certain kinds of tests, however, it may be desirable to specify a timeout value.