1

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?

borisivan
  • 71
  • 6
  • Interesting problem! I am curious to know as to how is TestNG running tests based on groups, when your suite file doesn't use that as a selection mechanism. TestNG uses groups as one of the selection mechanisms to help it decide which set of `@Test` methods are to be executed from the given `package` or `class` tags. Can you please help create some code which can be executed to see the problem ? – Krishnan Mahadevan Aug 29 '17 at 16:51
  • It may have been working in sequence by coincidence, re: the classes being 'in order' re: group. I guess bottom line the question is: is there any way to create multiple execution groups that aren't related to the testNG 'group' concept, and that testNG will still honor the @beforeGroup only firing once. – borisivan Aug 29 '17 at 17:42
  • @KrishnanMahadevan, I've noticed that some of the test classes spread across multiple execution groups (defined as 'tests' above...) are different classes from the same package. Could that be relevant? – borisivan Sep 29 '17 at 19:00

0 Answers0