TimeoutAttribute
Used on a method, marks the test with a timeout value in milliseconds.
The test will be run in a separate thread and is cancelled if the timeout
is exceeded. Used on a class or assembly, sets the default timeout
for all contained test methods.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using System;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class TimeoutAttribute : PropertyAttribute, IApplyToContext
{
private int _timeout;
public TimeoutAttribute(int timeout)
: base(timeout)
{
_timeout = timeout;
}
void IApplyToContext.ApplyToContext(TestExecutionContext context)
{
context.TestCaseTimeout = _timeout;
}
}
}