Skip to content
1 change: 1 addition & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"Maddock",
"Frans",
"Bouma",
"TIMESPAN",
"yowko"
],
"patterns": [
Expand Down
8 changes: 7 additions & 1 deletion docs/articles/nunit/writing-tests/attributes/maxtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
21 changes: 20 additions & 1 deletion docs/articles/nunit/writing-tests/attributes/timeout.md
Original file line number Diff line number Diff line change
@@ -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 <TIMESPAN>`.
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.
Expand Down