Search code examples
nunit

What happens if I specify a timeout value in nunit-console, but a smaller MaxTime in a specific test?


What happens if I specify --timeout in nunit console command line, and at a specific test, I specify a smaller MaxTime?

For example, in nunit console my timeout value is 600000 ms ( ie: 600 seconds), but in a test case, my MaxTime is 20000 ( ie: 20 seconds), what will happen?

My guess is that

  1. If the test is taking less than 20 seconds to run, then it passes
  2. If the test takes between 20 and 600 seconds to run, then the test can complete ( ie: no aborting), but will be marked with a failure.
  3. If the test takes more than 600 seconds to run, then the test will be aborted, and it will be marked with a failure.

Is my understanding correct?


Solution

  • I think you are mixing two different NUnit attribtues:

    If a test has a TimeoutAttribute, it will be cancelled when that timeout is exceeded. Cancellation is treated by NUnit as an error, rather than a failure, that is, there is something wrong with the test rather than the system under test. Most folks, however, tend to look at errors and failures as being the same... i.e. the test didn't pass.

    The timeout value, which may be specified as an argument to the console runner, should probably have been called "defaultTimeout", since that's what it is. When you specify that argument, all tests without their own TimeoutAttribute are treated as if they had an attribute with that default value. It doesn't matter whether the value is larger or smaller and there is no special treatment of timings between the two values.

    NUnit also has a MaxTimeAttribute, which doesn't cancel tests at all. Rather, it simply tracks the length of time used to run the test. If the test would otherwise have passed but exceeded the max time specified, it is marked as a failure.