testNG @beforeGroups and parallel tests and suite.xml file

403 views Asked by At

I have a a testNG suite made up of classes like this:

A

C (and many others) extends B, which extends A.

E (and many others) extends D, which extends A.

Tests are in classes C and E. Those tests are part of testNG groups, and the @beforeGroups method are in B and D, respectively.

For example, class C (and others) has an @Test with groups='b', and class B has the @beforeGroups method for that group. Similar pattern for the other group, I'll call 'd', where @beforeGroup is defined in class D.

This has been working fine when run in sequence -- the suite.xml file has one 'test' section with a 'classes' section, with all the 'class' entries. I don't reference any 'groups' inside the .xml file, and testNG is smart enough to run all the tests in a group first, then the next group, processing the @beforeGroup method as one would expect (once before group 'b', and once before group 'd').

The execution time is growing to the point where I would like to run some of these in parallel. Would like to break up into 4 parallel executions, each containing some classes, where those classes run in sequence. And the @beforeGroups must only execute ONCE for that group regardless if that group's classes are split into more than 1 of the parallel executions -- that's the part giving me grief now. For example, if I have the following:

number of classes (example: C) in group 'b': 10

number of classes (example: E) in group 'd': 20

I'd like to do the following:

parallel execution 1: 3 of 10 classes that extend B (and in group='b')

parallel execution 2: 7 of 10 classes that extend B (and in group='b')

parallel execution 3: 10 of 20 classes that extend D (and in group='d')

parallel execution 4: 10 of 20 classes that extend D (and in group='d')

I tried setting up the suite.xml file like this:

<suite name="suiteName" verbose="1" parallel="tests" thread-count="10">
  <test name="parallel1" time-out="300000">
        <classes>
            <class name="com.xxxxx.classes1-3" />
        </classes>
  </test>

  <test name="parallel2" time-out="300000">
        <classes>
            <class name="com.xxxx.classes4-10" />
        </classes>
  </test>

  <test name="parallel3" time-out="300000">
        <classes>
            <class name="com.xxxx.classes11-20" />
        </classes>
  </test>

  <test name="parallel4" time-out="300000">
        <classes>
            <class name="com.xxxx.classes21-30" />
        </classes>
  </test>
</suite>

The problem is that after this change, the @beforeGroups code is running multiple times (twice for each group, I think), instead of just once. I'm sure it has something to do with the fact that I've separated each group across multiple 'test' sections of the suite.xml file, where before they were all in one 'test'.

Any suggestions?

0

There are 0 answers