1
package testng.paralellwithannotations;
3
import static org.testng.Assert.*;
4
import org.testng.annotations.AfterSuite;
5
import org.testng.annotations.BeforeSuite;
6
import org.testng.annotations.Test;
10
* Test that parallel tests actually run and complete within the expected time.
12
public class TestNGParallelTest{
14
static int testCount = 0;
15
static long startTime;
17
@BeforeSuite(alwaysRun = true)
18
public void startClock(){
19
startTime = new Date().getTime();
22
@AfterSuite(alwaysRun = true)
23
public void checkTestResults(){
24
long runtime = new Date().getTime() - startTime;
25
System.out.println("Runtime was: " + runtime);
26
assertTrue( testCount == 3, "Expected test to be run 3 times, but was " + testCount);
27
// Note, this can be < 1000 on Windows.
28
assertTrue( runtime < 1400, "Runtime was " + runtime + ". It should be a little over 1000ms");
31
@Test(threadPoolSize = 2, invocationCount=3)
32
public void incrementTestCountAndSleepForOneSecond() throws InterruptedException {
35
System.out.println("Ran test");
38
private synchronized void incrementTestCount() {