Home > WaitUtils

WaitUtils

WaitUtils is a project mainly written in Java, based on the View license.

A library that eliminates the need for blind sleeps in tests

h2. Problem

A typical problem one has to solve while writing higher level tests - functional tests, integration tests etc, is that there is a need to wait for some operation to finish.

For example, lets say we are testing on an Email Client. Clicking on a Delete button issues an AJAX call which deletes an email. Now, the test itself needs to wait until the delete action returns. If not, the test continues and most likely fail.

There are a few ways of solving this issue. The most obvious way to do this is by doing a sleep in the test. Where it gets tricky is to figure out how long to sleep for. A small value would mean the test does not wait for long enough and fail. Large value, instead, means that the test sleeps for too long, wasting a lot of time even though the result is available.

The key is to find out a way to be optimal in how long the test waits.

h2. Solution

WaitUtils solves this problem by providing APIs that internal does a retry after every 100 ms and does so until some condition is true.

Checkout the API documentation on how to use the WaitUtils. All methods are static and follow the same philosophy as the JUnit asserts and hamcrest matchers.