【问题标题】:@BeforeClass in TestNG is not executed in parallel with parallel = instancesTestNG 中的 @BeforeClass 不与 parallel = 实例并行执行
【发布时间】:2016-12-30 05:06:43
【问题描述】:

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

我在这里错过了什么?

这是我的测试代码 -

@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());
}

【问题讨论】:

  • 这有什么更新吗?

标签: multithreading parallel-processing testng testng-dataprovider


【解决方案1】:

试试@BeforeClass(alwaysRun = true)

【讨论】:

    猜你喜欢
    • 2021-05-26
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 2020-03-01
    相关资源
    最近更新 更多