TimeOut for Configuration Annotations of TestNG

Oldest developers can't recall the times when TestNG introduced timeout constraints for tests methods (invocationTimeOut parameter of @Test annotation). The current beta of TestNG allows to set timeouts also for configuration methods.

This is a handy feature especially for integration or end-to-end tests.

Lately in our project we encountered the following problem. In some set up method (annotated with @BeforeClass) we called some web service in order to fill the test database with required data (data of users, permissions etc.). When the service was not available the tests lasted forever (well, almost) and the logs gave no clear reason of what happened.

We came with a workaround (putting configuration code into some test method and make other methods depend on it) but it was clear that what we really need is a framework support for this feature. The funny thing was, that when I entered the TestNG mailing group at Google I found the same question asked by another user about 3 hours earlier. :) Seems like we bounced the same wall simultaneously. :)

For those interested here is the link to the discussion at TestNG mailing list: http://groups.google.com/group/testng-users/browse_thread/thread/0104282...

The functionality is now in beta and I assume it will appear in the next release of TestNG (5.15). From my simple tests it seems to work fine and gives a clear error message:
org.testng.internal.thread.ThreadTimeoutException: Method
org.testng.internal.ConfigurationMethod.beforeClass() didn't finish
within the time-out 2500

Here comes a snippet of testng-results.xml file:

<test-method status="FAIL" signature="beforeClass()"
name="beforeClass" is-config="true" duration-ms="0" started-
at="2010-10-03T20:55:59Z" finished-at="2010-10-03T20:55:59Z">
          <exception
class="org.testng.internal.thread.ThreadTimeoutException">
            <message>
              <![CDATA[Method
org.testng.internal.ConfigurationMethod.beforeClass() didn't finish
within the time-out 2500]]>
            </message>
            <full-stacktrace>
              <!
[CDATA[org.testng.internal.thread.ThreadTimeoutException: Method
org.testng.internal.ConfigurationMethod.beforeClass() didn't finish
within the time-out 2500
        at java.util.concurrent.FutureTask
$Sync.innerSetException(FutureTask.java:273)
        at java.util.concurrent.FutureTask
$Sync.innerRun(FutureTask.java:307)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:619)
]]>
            </full-stacktrace>
          </exception>
        </test-method>

Links

in our project

Lately in our project we encountered the following problem. In some set up method (annotated with @BeforeClass) we called some web service in order to fill the test database with required data (data of users, permissions etc.). When the service was not available the tests lasted forever (well, almost) and the logs gave no clear reason of what happened.

 
 
 
This used to be my blog. I moved to http://tomek.kaczanowscy.pl long time ago.

 
 
 

Please comment using