Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

The timeOut attribute in TestNG sets the maximum time, in milliseconds, that a test method is allowed to run. If the method takes longer than that limit, TestNG interrupts it, marks the test as failed, and reports a ThreadTimeoutException. It prevents slow, hung, or infinite-loop tests from blocking the rest of your suite.
For example, @Test(timeOut = 5000) allows the method five seconds; if it runs past that, TestNG terminates it. You can apply timeouts at the method level through the @Test annotation or globally through the testng.xml suite file.
TestNG runs each timed method in a separate worker thread and watches how long it takes. When the elapsed time crosses the configured timeOut value, TestNG interrupts that thread and records the result as a failure rather than allowing the method to hang indefinitely. This behavior is essential in continuous integration pipelines, where a single stuck test could otherwise freeze an entire build.
The value is always expressed in milliseconds, so 1000 equals one second. A timeout is useful for performance-sensitive assertions, API calls bound by a Service Level Agreement (SLA), and any operation that could loop forever. To learn how timeouts fit alongside other annotations, see the TestMu AI TestNG framework tutorial.
The most common approach is to declare the timeout directly on the @Test annotation. This keeps the limit close to the method it governs and overrides any suite-wide default. In the example below, the method is expected to finish within two seconds, but the simulated three-second delay forces a timeout failure.
import org.testng.annotations.Test;
public class TimeoutTest {
@Test(timeOut = 2000) // limit is 2000 ms (2 seconds)
public void testWithTimeout() throws InterruptedException {
// Simulates work that takes 3 seconds
Thread.sleep(3000);
// TestNG interrupts this method at 2000 ms and marks it failed
}
}When this runs, TestNG fails the method with org.testng.internal.thread.ThreadTimeoutException because it did not complete inside the allotted window.
To apply one default limit across many methods, add a time-out attribute to the <suite> or <test> tag in your testng.xml file. Any method that declares its own @Test timeOut will still override this value for itself.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="RegressionSuite" time-out="5000">
<test name="SmokeTests">
<classes>
<class name="com.example.TimeoutTest" />
</classes>
</test>
</suite>Here every method under the suite inherits a 5000 ms limit unless it specifies otherwise. This is a clean way to enforce a baseline SLA across a large regression run.
TestNG offers a second timing attribute for repeated executions. Knowing the difference prevents confusing failures:
Timeout values behave differently across browsers, operating systems, and network conditions, so testing on a single local machine can hide false positives and negatives. With TestMu AI, you can run the same TestNG suite across 3000+ real browsers and operating systems on a scalable cloud Selenium automation grid, calibrating timeouts against realistic latency instead of a fast local loopback.
Running in parallel across the cloud also shortens overall suite time, which lets you keep sensible per-method limits without extending the total build. Explore how TestMu AI handles large TestNG suites through its cross browser testing platform.
The TestNG timeOut attribute is a simple but powerful guardrail: it defines, in milliseconds, how long a test method may run before TestNG fails it. Apply it at the method level for precise control, use testng.xml for suite-wide defaults, and reach for invocationTimeOut when a method repeats. Combined with explicit waits and a realistic cloud grid, timeouts keep your automation fast, deterministic, and free of hung builds.
The timeOut value is always defined in milliseconds. A value of 5000 means five seconds and 2000 means two seconds. TestNG has no separate unit for seconds, so you must convert your intended limit into milliseconds before assigning it to the timeOut attribute.
When a test method exceeds its timeOut limit, TestNG interrupts the thread and fails the test with org.testng.internal.thread.ThreadTimeoutException. The report shows the method as failed rather than skipped, along with the configured limit and the actual time taken.
Yes. Add a time-out attribute to the suite or test tag in testng.xml. This applies a default limit to every method under that scope. A timeOut declared on an individual @Test annotation overrides the suite-level value for that specific method.
timeOut limits a single invocation of a test method. invocationTimeOut caps the combined time of all invocations when a method runs multiple times through invocationCount. Use invocationTimeOut together with invocationCount for repeated or load-style executions.
Yes. Each method still enforces its own timeOut when tests run in parallel threads. However, heavy parallelism can slow individual threads, so set timeouts with enough headroom to avoid false failures caused by shared CPU or network contention.
Yes, but choose realistic values. UI tests involve page loads and network calls, so a value that is too low causes flaky failures. Combine a generous TestNG timeOut with explicit waits inside the test for reliable, deterministic Selenium automation.
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.

TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance