TestNG中的@BeforeClass不与parallel = instances并行执行

时间:2021-08-16 13:50:23

I have a testng factory creating test instances having single @Test method. With "parallel=instances" and thread-count = "10" specified in testng.xml, I expect @BeforeClass to execute in parallel. Whereas I see the @BeforeClass of other threads is blocked on execution till the current @BeforeClass execution is complete. i.e prints "In Before Class" in sequence with 2 second delay.

我有一个testng工厂创建具有单个@Test方法的测试实例。在testng.xml中指定“parallel = instances”和thread-count =“10”时,我希望@BeforeClass并行执行。我看到其他线程的@BeforeClass在执行时被阻止,直到当前的@BeforeClass执行完成。即按顺序打印“In Before Class”,延迟2秒。

What am I missing here ?

我在这里错过了什么?

Here is my test code -

这是我的测试代码 -

@BeforeClass
public void beforeClass() throws InterruptedException{
    System.out.println("In Before Class ::: " + Thread.currentThread().getId());
    Thread.sleep(2000);
}


@Test
public void test(){
    System.out.println("In Test ::: " + Thread.currentThread().getId());
}

@AfterClass
public void afterClass(){
    System.out.println("In After Class ::: " + Thread.currentThread().getId());
}

1 个解决方案

#1


Try @BeforeClass(alwaysRun = true)

试试@BeforeClass(alwaysRun = true)

#1


Try @BeforeClass(alwaysRun = true)

试试@BeforeClass(alwaysRun = true)