dcsimg
Timeout doesn't stop the test
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Oleg_Aravin
Posted On:   Wednesday, March 31, 2010 06:55 AM

Hi all, I have a problem with junit timeout. The test doesn't stop after timeout time, and continue to working in the second test. This is my code: public class Temp { @Test(timeout = 1000) public void test1() { int i =0; while (true) { System.out.println("test 1: " + i++); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } } @Test public void test2() { for (int i = 0; i < 10; i++) { System.out.println("test 2: " + i); try { Thread.sleep(500); } catch (InterruptedException e) { e.print   More>>

Hi all,

I have a problem with junit timeout. The test doesn't stop after timeout time, and continue to working in the second test.
This is my code:


			
public class Temp {

@Test(timeout = 1000)
public void test1() {
int i =0;
while (true) {
System.out.println("test 1: " + i++);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

@Test
public void test2() {
for (int i = 0; i < 10; i++) {
System.out.println("test 2: " + i);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
}


After running this class I took following output:

			
test 1: 0
test 1: 1
test 1: 2
test 2: 0
test 1: 3
test 2: 1
test 1: 4
test 2: 2
test 1: 5
test 2: 3
test 1: 6
test 2: 4
test 1: 7
test 2: 5
test 1: 8
test 2: 6
test 1: 9
test 2: 7
test 1: 10
test 2: 8
test 1: 11
test 2: 9
test 1: 12

How can I stop the body of the test1() after 1 second?    <<Less
About | Sitemap | Contact