views:

169

answers:

2

Hi gents and ladies,

I'm responsible for allowing unit tests for one of ETL components.I want to acomplish this using testNG with generic java test class and number of test definitions in testng.xmlpassing various parameters to the class.Oracle and ETL guys should be able to add new tests without changing the java code, so we need to use xml suite file instead of annotations.

Question

Is there a way to group tests in testng.xml?(similarly to how it is done with annotations) I mean something like

<group name="first_group">
   <test>
   <class ...>
   <parameter ...>
   </test>
</group>

<group name="second_group">
 <test>
   <class ...>
   <parameter ...>
   </test>
</group>

I've checked the testng.dtd as figured out that similar syntax is not allowed.But is therea workaround to allow grouping?

Thanks in advance

A: 

You can specify groups within testng.xml and then run testng using -groups

<test name="Regression1">
  <groups>
    <run>
      <exclude name="brokenTests"  />
      <include name="checkinTests"  />
    </run>
  </groups>
  ....
Brian Agnew
Thanks, Brian.But that's not what i want : <groups> can aggregate groups in a single meta-group, while i need to group classes in a meta-group.Coming back to your example, the problem is how to add particular tests(not other groups) to each of "brokenTests" and "checkinTest" groups
diy
A: 

Hi,

No, this is not possible at the moment.

As a rule of thumb, I don't like adding information in XML that points into Java code, because refactorings might silently break your entire build.

For example, if you rename a method or a class name, your tests might start mysteriously breaking until you remember you need to update your XML as well.

Feel free to bring this up on the testng-users mailing-list and we can see if there's interest for such a feature.

--

Cedric

Cedric Beust
Thanks, Cedric.is there any workaround to allow test grouping outside the java code?For the time being,the most attractive approach i can come up with is creating xml test suite per group
diy
I suggested a work around on the list, which I'll repeat here:You could do this yourself as a pre-test task: implement a code generator that takes the information in XML form, grab the corresponding Java source file and generate a TestNG source file with all the annotations placed in the right locations. And then you run TestNG on that file.
Cedric Beust