Groups section: <groups>

In the <groups> section, users can include or exclude groups of tests to run, provided they have tagged the test methods with the groups attribute. This allows users to change the type of suite to run on the fly to create a smoke test, feature test, regression test, and so on.

TestNG also allows a BeanShell expression to be inserted in the XML file, which will disable the <groups> section of the suite file, but allows more flexibility in filtering tests. Here is an example of include/exclude of groups, building on the suite section:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="My_Test_Suite" preserve-order="true" parallel="false"
thread-count="1" verbose="2">

<!-- groups: "regression", "smoke", "limit", "stress", etc... -->
<groups>
<run>
<include name = "SMOKETEST" />
<!-- include name = "LIMIT" / -->
<!-- include name = "REGRESSION" / -->
<!-- include name = "POSITVE" / -->
<exclude name = "NEGATIVE" />
</run>
</groups>

...

Now, here is an example using the BeanShell expression:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="My_Test_Suite" preserve-order="true" parallel="false"
thread-count="1" verbose="2">

<!-- tests -->
<test name="My_Test_Name">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
String testGroups = "SMOKETEST,LIMIT";
String [] splitTestGroups =
testGroups.split(",");

for ( String group : splitTestGroups ) {
if ( groups.containsKey(group) ) {
return true;
}
}

return false;
]]>
</script>
</method-selector>
</method-selectors>

...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.144.32