Sudharshan Ramaiah
Sudharshan Ramaiah

Reputation: 179

Run testNG tests based on "priority" of test cases

Is it possible to run TesNG tests based on priority? For example, say I want to run only the tests which have priority=1.

<testng outputDir="${report.dir}" haltOnFailure="true" groups="${groups}">

    <!-- Extra project classpath-->
    <!-- Tell Ant where is the project and test classes -->
   <classpath refid="selenium.classpath" />
   <classpath refid="dynamicreports.classpath" />   


    <!-- Tell Ant what test classes need to run -->
    <classfileset dir="${bin.dir}" includes="**/*.class" />

</testng>

Upvotes: 1

Views: 399

Answers (2)

Jaroslav Cincera
Jaroslav Cincera

Reputation: 1036

Yes, you can do it using BeanShell script in TestNG XML suite definition. Something like:

<method-selector>
    <script language="beanshell">
        <![CDATA[ testngMethod.getPriority() > 1 ]]>
    </script>
</method-selector>

See http://testng.org/doc/documentation-main.html#beanshell for more details.

Upvotes: 2

Gosaka
Gosaka

Reputation: 191

You can have Groups to do this for you . Assign a group to the testcase according to the priority and run only that group

http://testng.org/doc/documentation-main.html#test-groups

Upvotes: 1

Related Questions