For Testing
For Testing

Reputation: 421

Correct way of grouping tests in TestNG

I am new to TestNG. We are trying to implement POM framework for automation testing. We are using WebDriver, Java, TestNG and TestLink. After executing test cases I am sending result to TestLink.

I have created bunch of test scripts. Each of my test scripts has many test cases. Sometimes we might want to run specific tests for specific release. What is the easiest way to manage this? I know we can disable tests in TestNG but I might have to manually go and update many of my test scripts. I feel group functionality in TestNg is not that good. Any suggestions?

Upvotes: 2

Views: 2661

Answers (2)

blurfus
blurfus

Reputation: 14031

You can use annotations in your test cases:

i.e.

 @Test(groups = { "FUNCTIONAL_TEST_GROUP" })

Or

   @Test(groups = { "REGRESSION_TEST_GROUP" })

UPDATE

If you are using Maven to run your tests, you can specify which ones to run from the command line like this:

mvn test -Dgroups=FUNCTIONAL_TEST_GROUP,REGRESSION_TEST_GROUP

If you are not using Maven, you can specify which tests to run in a your suite.xml file; like this:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="TestAll">

  <test name="RegressionTest">
    <groups>
        <run>
            <exclude name="FUNCTIONAL_TEST_GROUP" />
            <include name="REGRESSION_TEST_GROUP" />
        </run>
    </groups>

    <!-- List all tests to include in this suite -->     
    <classes>
        <class name="com.path.to.your.tests" />
    </classes>

    <!-- OR include all packages -->
    <packages>
        <package name=".*" ></package>   
    </packages>

  </test>

</suite>

Upvotes: 1

d3ming
d3ming

Reputation: 9070

My team uses groups kind of like 'tags', since you can add more than one group per test. This allows you to put different pivots on your tests.

For example, given a simple login test can have something like:

@Test(groups = {"login", "basic", "acceptance"}

In this way, you can associate this test for anytime someone changes the login code and for whenever you do your basic test suite run but also include it in the larger 'acceptance' suite.

Upvotes: 2

Related Questions