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 c51ebf313..8200778e8 100644 --- a/docs/articles/nunit/writing-tests/attributes/maxtime.md +++ b/docs/articles/nunit/writing-tests/attributes/maxtime.md @@ -21,4 +21,10 @@ 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. + +## 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 6df9d6ee9..232a158b7 100644 --- a/docs/articles/nunit/writing-tests/attributes/timeout.md +++ b/docs/articles/nunit/writing-tests/attributes/timeout.md @@ -1,7 +1,26 @@ # 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 due to limitations in the runtime. +> 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 + +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 `. +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 + +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 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.