question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@BeforeClass not executed in parallel when parallel="instances"

See original GitHub issue

I personally came across the source of my problem when I found this stack overflow thread which helped me make sense of some strange behavior I’ve been encountering with a Factory + DataProvider + Parallel Instances

http://stackoverflow.com/questions/30027872/beforeclass-in-testng-is-not-executed-in-parallel-with-parallel-instances

It doesn’t look like a bug was ever filed, but I am getting burned with my selenium tests queueing against the grid, and waiting for a browser in the @BeforeClass annotation which sets up my test in a parent class. The child class has a @Factory to create all the instances up front, and the @Test method to actually carry out the test. The problem is that once a browser hits the grid queue, no other tests will start up, even though there are plenty of instances available (we test against various browsers, so having 1 browser flavor queue up doesn’t mean that the grid is completely busy).

The example posted in the stack overflow thread is:

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

I am running 6.9.9.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18

github_iconTop GitHub Comments

1reaction
krmahadevancommented, Apr 19, 2019

The fix should be available either in the next beta version or the released version of TestNG.

0reactions
ghostcommented, Apr 16, 2019

Has anyone found a workaround?

Read more comments on GitHub >

github_iconTop Results From Across the Web

multithreading - @BeforeClass in TestNG is not executed in ...
I have a testng factory creating test instances having single @Test method. With "parallel=instances" and thread ...
Read more >
@Beforeclass in TestNg is not executed in parallel with ...
Hi,. I have a testng factory creating test instances having single @Test method. With "parallel=instances" and thread-count = "10" specified ...
Read more >
Exception in a @BeforeClass method in a JUnit suite class ...
I have a @BeforeClass annotated method in a JUnit test suite class ... If the build is started without the parallel parameter it...
Read more >
CHANGES.txt - platform/external/testng - Git at Google
Fixed: The XML parser doesn't recognize parallel="instances" ... Fixed: @BeforeClass methods were not running in parallel (Aidan Short).
Read more >
Parallel Tests Execution - Confluence Mobile - Experitest
The test developed using the strategy above will not give reliable results. The reason being that Appium Driver created in @BeforeClass ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found