public class TimeOuts {
@Test (timeOut = 1000)
public void myTestMethod() throws InterruptedException {
System.err.println("Commencing sleep");
Thread.sleep(1500);
System.err.println("Sleep completed");
}
public static void main(String[] args) {
TestNG testNG = new TestNG();
testNG.setVerbose(2);
testNG.setTestClasses(new Class[] {TimeOuts.class});
String version = new File(TestNG.class.getProtectionDomain().getCodeSource()
.getLocation().getFile()).getParentFile().getName();
System.err.println("TestNG Version : " + version);
testNG.run();
}
}
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
import org.testng.annotations.Test;
public class TestTimeout {
@Test public void test1(){ System.out.println("test1 started."); try{ Thread.sleep(10 * 1000); }catch(Exception e){} System.out.println("test1 finished."); }
@Test public void test2(){ System.out.println("test2 started."); try{ Thread.sleep(10 * 1000); }catch(Exception e){} System.out.println("test2 finished."); }}
public class TestTimeoutMain {
public static void main(String[] args) throws Exception{ String suiteFile = "test-timeout.xml";
List<XmlSuite> suites = new Parser(suiteFile).parseToList();
TestNG testng = new TestNG(); testng.setXmlSuites(suites); testng.run(); }}
test-timeout.xml:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Test time out" parallel="tests" time-out="1000">
<test name="TimeoutTest" preserve-order="true"> <classes> <class name="TestTimeout"/> </classes> </test>
</suite>
public class TestTimeout {
@Test(timeOut = 1000)
public void test1(){ System.out.println("test1 started."); try{ Thread.sleep(10 * 1000); }catch(Exception e){} System.out.println("test1 finished."); }
@Test(timeOut = 1000)
public void test2(){ System.out.println("test2 started."); try{ Thread.sleep(10 * 1000); }catch(Exception e){} System.out.println("test2 finished."); }}
public class TimeOuts {
@Test (timeOut = 1000)
public void myTestMethod() {
try {
System.err.println("Commencing sleep");
Thread.sleep(1500);
System.err.println("Sleep completed");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TestNG testNG = new TestNG();
testNG.setVerbose(2);
testNG.setTestClasses(new Class[] {TimeOuts.class});
String version = new File(TestNG.class.getProtectionDomain().getCodeSource()
.getLocation().getFile()).getParentFile().getName();
System.err.println("TestNG Version : " + version);
testNG.run();
}
}
public class TimeOuts {
@Test (timeOut = 1000)
public void myTestMethod() {
try {
System.err.println("Commencing sleep");
Thread.sleep(1500);
System.err.println("Sleep completed");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TestNG testNG = new TestNG();
testNG.setVerbose(2);
// testNG.setParallel("tests");
// If setParallel("tests") is commented out then timeout happens else there are
// no timeouts.
testNG.setTestClasses(new Class[] {TimeOuts.class});
String version = new File(TestNG.class.getProtectionDomain().getCodeSource()
.getLocation().getFile()).getParentFile().getName();
System.err.println("TestNG Version : " + version);
testNG.run();
}
}