[testng-dev] TimeOuts not working when launching TestNG from code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[testng-dev] TimeOuts not working when launching TestNG from code

Andres Antonen
I am trying to run a test using an instance of TestNG class. The code looks something like this:

import org.testng.TestNG;
import org.testng.annotations.Test;


public class TestNGHangTest {
 
private class ExampleTest {
 
@Test
 
private void iWorkWell() {
 
System.out.println("Test1");
 
}
 
@Test(timeOut = 100, dependsOnMethods= {"iWorkWell"})
 
private void iHangHorribly() {
 
System.out.println("Test2");
 
while (true) {
 
int two = 1 + 1;
 
}
 
}
 
@Test(dependsOnMethods= {"iHangHorribly"})
 
private void iAmNeverRun() {
 
System.out.println("Test3");
 
}
 
}
 
public static void main(String[] args) {
 
TestNG testng = new TestNG();
 testng
.setTestClasses(new Class[] { ExampleTest.class });
 testng
.run();
 
}
}

The infinite loop should be killed and the third test skipped, but the thread running the loop never ends. When the same inner class is tested using Eclipse's TestNG plugin, it works as expected.
Since the code does not exit properly, it does not generate a report and wastes CPU cycles, forcing me to terminate JVM manually.

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-dev.
For more options, visit https://groups.google.com/d/optout.