timeouts in testNG

133 views
Skip to first unread message

testng...@opensymphony.com

unread,
Apr 19, 2005, 8:51:35 AM4/19/05
to testng...@googlegroups.com
hi,

how do i define timeouts for a single test method ?

do i have to put the timeout tag to the test method directly (like for java 1.4 into javadoc @testng.test timeOut = "20") or do i have to put the timeout tag into the test-tag inside the testng.xml ?

thanks a lot,
oliver

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=1675&messageID=5129#5129

Alexandru Popescu

unread,
Apr 19, 2005, 10:11:13 AM4/19/05
to testng...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[quote testng...@opensymphony.com::on 4/19/2005 2:51 PM]
For JDK 1.5. @Test(timeOut=100L)
For JDK 1.4 @testng.test timeOut="100"

- --:alex |.::the_mindstorm::.|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCZRGBOCPjdDT2FEURAtbCAJ97RHfViSq5GN8IT79hhj+6FrwenQCgwAjC
wiQEd0H++Htwehqw/06l85k=
=+sns
-----END PGP SIGNATURE-----

testng...@opensymphony.com

unread,
Apr 20, 2005, 7:15:50 AM4/20/05
to testng...@googlegroups.com
thanks for your answer, but that was what i did and it didn't work, so maybe i dont understand the usage of the timeout-tag right ?

when i have this absurd test method:

public void absurdTest() {
   synchronized (this) {
   try {
     this.wait(9000);
   } catch (InterruptedException e) {
     Assert.assertTrue(false);
   }
   }
  
   Assert.assertTrue(true);
}
testNG works ok -> Total tests run: 1, Failures: 0, Skips: 0

when i increase the value for waiting inside the test method as "this.wait(11000);"
testNG doesnt recognize the test -> Total tests run: 0, Failures: 0, Skips: 0, imho this is, because the defautl timeout value for test methods is 10 seconds and therefore the test method didnt finish within time.

so i increase the timeout value for the test method in the javadoc (for java 1.4):
@testng.test timeOut="200"
but the test method still isnt't run (even if i further increase the timeout value) ..
on the result page for the test methode, there always is printed "Total time: 10 seconds"

what can i do ?

thanks a lot ...

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=1675&messageID=5216#5216

Cedric Beust

unread,
Apr 20, 2005, 10:19:38 AM4/20/05
to testng...@googlegroups.com
I'm not seeing any @Test on your absurdTest() method, but I assume you
forgot to copy it?

Here is how we test time-outs for TestNG, can you try this and let us know
what happens?

public class TimeOutTest {

@Test(timeOut = 5000 /* 5 seconds */)
public void timeoutShouldPass() {
}

@Test(timeOut = 5 * 1000 /* 5 seconds */)
public void timeoutShouldFailByException() {
throw new RuntimeException("EXCEPTION SHOULD MAKE THIS METHOD FAIL");
}

@Test(timeOut = 1000 /* 1 second */)
public void timeoutShouldFailByTimeOut() throws InterruptedException {
Thread.sleep(10 * 1000 /* 10 seconds */);
}

--
Cédric
http://beust.com/weblog

Alexandru Popescu

unread,
Apr 20, 2005, 11:23:24 AM4/20/05
to testng...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[quote testng...@opensymphony.com::on 4/20/2005 1:15 PM]
The following test is failing (as expected):

package net.noco.testng.jdk15;

import com.beust.testng.annotations.Test;

import static com.beust.testng.Assert.fail;

public class TimeoutTest {
@Test(timeOut=1000L)
public void timeLimitted() {
try {
Thread.sleep(2000L);
}
catch(InterruptedException ie) {
fail("Thread was interrupted", ie);
}
}
}

If timeOut is modified to 3000L it is passing.

The same happens for:
@Test(timeOut=1000L)
public void timeLimitted() {
synchronized(this) {
try {
wait(2000L);
}
catch(InterruptedException ie) {
fail("Thread was interrupted", ie);
}
}
}

Can you tell me what TestNG version are you using? If still getting the failures pls send me
privately a zip containing a failing test case if possible.

cheers,

- --:alex |.::the_mindstorm::.|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCZnPrOCPjdDT2FEURAnMgAKCoUjbpqX8VXVMn7U/Lz0J3d+BISACgmBBs
YZIX3WkTcortbCtGzaVQdWw=
=m3ym
-----END PGP SIGNATURE-----

testng...@opensymphony.com

unread,
Apr 20, 2005, 10:28:37 AM4/20/05
to testng...@googlegroups.com
hi cedric,

i did'nt copy the javadoc syntax (i'm using java 1.4)..-> the full syntax of the test method is like (also tried withoud the "" and with 20000L as alexandru popescu posted):
/**
* @testng.Test timeOut="20000"
*/
public void insertConditionsTest() {
synchronized (this) {
try {
this.wait(11000);
} catch (InterruptedException e) {
Assert.assertTrue(false);
}
}

Assert.assertTrue(true);
}


when this methd is executed, the result is :
Total tests run: [b]0[/b], Failures: 0, Skips: 0

afaik, the result should be like
Total tests run: [b]1[/b] when the test method results as OK (when the timeout of 20 seconds is handled)

any further ideas ?

tia,
oliver

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=1675&messageID=5233#5233

Alexandru Popescu

unread,
Apr 20, 2005, 11:47:32 AM4/20/05
to testng...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[quote testng...@opensymphony.com::on 4/20/2005 4:28 PM]
> hi cedric,
>
> i did'nt copy the javadoc syntax (i'm using java 1.4)..-> the full syntax of the test method is like (also tried withoud the "" and with 20000L as alexandru popescu posted):
> /**
> * @testng.Test timeOut="20000"
> */
> public void insertConditionsTest() {
> synchronized (this) {
> try {
> this.wait(11000);
> } catch (InterruptedException e) {
> Assert.assertTrue(false);
> }
> }
>
> Assert.assertTrue(true);
> }
>
>
> when this methd is executed, the result is :
> Total tests run: [b]0[/b], Failures: 0, Skips: 0
>
> afaik, the result should be like
> Total tests run: [b]1[/b] when the test method results as OK (when the timeout of 20 seconds is handled)
>
> any further ideas ?
>
> tia,
> oliver
>

The javadoc annotation is @testng.test (not @testng.Test).

- --:alex |.::the_mindstorm::.|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCZnmUOCPjdDT2FEURAt8lAJ4vuyaqEwqppl39Nyljz+w5QzmyRQCfUuT3
Wv0avEymFWZuI1H3Jnc3H0k=
=J97Q
-----END PGP SIGNATURE-----

testng...@opensymphony.com

unread,
Apr 20, 2005, 11:25:02 AM4/20/05
to testng...@googlegroups.com
hi alexandru,

thx a lot on helping me out ;-) it works fine now.

if i remember correct, i wrote "@testng.test" in the beginning, and put "@testng.Test" after some try-and-error with different timeout values...

thx a lot & lg,
oliva

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=1675&messageID=5236#5236

Yung-Lin Ho

unread,
May 4, 2006, 7:27:26 PM5/4/06
to testng...@googlegroups.com
>
> I'm not seeing any @Test on your absurdTest() method,
> but I assume you
> forgot to copy it?
>
> Here is how we test time-outs for TestNG, can you try
> this and let us know
> what happens?
>
> public class TimeOutTest {
>
> @Test(timeOut = 5000 /* 5 seconds */)
> public void timeoutShouldPass() {
> }
>
> @Test(timeOut = 5 * 1000 /* 5 seconds */)
> public void timeoutShouldFailByException() {
> throw new RuntimeException("EXCEPTION SHOULD MAKE
> THIS METHOD FAIL");
> }
>
> @Test(timeOut = 1000 /* 1 second */)
> public void timeoutShouldFailByTimeOut() throws
> InterruptedException {
> Thread.sleep(10 * 1000 /* 10 seconds */);
> --
> Cédric
> http://beust.com/weblog
>


I have a similar question about timeouts in TestNG. I've run the following code under testng4.6-jdk1.5 and testng4.7beta-jdk1.5. The timeoutShouldFailByTimeOut method would pass the test.

It looks like the timeOut attribute is only appliable to test methods but not test classes.

@TimeOutTest ( timeOut = 5000L)
public class Test {
@Test()
public void timeoutShouldPass() { }

@Test()


public void timeoutShouldFailByException() {
throw new RuntimeException("EXCEPTION SHOULD MAKE THIS METHOD FAIL");
}

@Test()


public void timeoutShouldFailByTimeOut() throws InterruptedException {
Thread.sleep(10 * 1000 /* 10 seconds */);
}
}

---------------------------------------------------------------------
Posted via Jive Forums

http://forums.opensymphony.com/thread.jspa?threadID=1675&messageID=57097#57097

Eran

unread,
May 4, 2006, 8:00:07 PM5/4/06
to testng...@googlegroups.com
Hi,

As far as I know the timeout attribute applies only to methods.
How do you interpret class level timeout? does it apply to each method separately? the combined time of all the methods? what about inherited test methods?

Regards,
Eran

Claude Quezel

unread,
May 5, 2006, 8:11:37 AM5/5/06
to testng...@googlegroups.com
This topic is covered in the tutorial here:

http://membres.lycos.fr/cquezel/


---------------------------------------------------------------------
Posted via Jive Forums

http://forums.opensymphony.com/thread.jspa?threadID=1675&messageID=57197#57197

Reply all
Reply to author
Forward
0 new messages