addTime method

void addTime (Duration duration)

Increase the timeout for the current test by the given duration.

Tests by default time out after two seconds, but the timeout can be increased before an expensive operation to allow it to complete without hitting the test timeout.

By default, each pump and pumpWidget call increases the timeout by a hundred milliseconds, and each matchesGoldenFile expectation increases it by several seconds.

In general, unit tests are expected to run very fast, and this method is usually not necessary.

The granularity of timeouts is coarse: the time is checked once per second, and only when the test is not executing. It is therefore possible for a timeout to be exceeded by hundreds of milliseconds and for the test to still succeed. If precise timing is required, it should be implemented as a part of the test rather than relying on this mechanism.

See also:

  • defaultTestTimeout, the maximum that the timeout can reach. (That timeout is implemented by the test package.)

Implementation

void addTime(Duration duration) {
  assert(_timeout != null, 'addTime can only be called during a test.');
  _timeout += duration;
}