79180340

Date: 2024-11-12 08:39:16
Score: 0.5
Natty:
Report link

Though the suggested answer by Krishnan works fine, there's a way to do it using just the TestNG xml file and @Parameter annotation without using DataProvider at all. It may be bulky, especially for bigger projects but it does exactly what arctic_monkey asked about, maybe someone will find it useful.

You can create multiple test tags with different parameter values but the same tests executed in each tag:

<suite name="Parameterized tests">
    <test name="Login Tests one">
        <parameter name="one"/>
        <classes>
            <class name="test.java.Login"/>
        </classes>
    </test>
    <test name="Login Tests two">
        <parameter name="two"/>
        <classes>
            <class name="test.java.Login"/>
        </classes>
    </test>
</suite>

You can also indicate particular methods in each class tag not to run the entire suite multiple times, but just the parameterized methods:

<suite name="Parameterized tests">
    <test name="Login Tests one">
        <parameter name="one"/>
        <classes>
            <class name="test.java.Login">
                <methods>
                    <include name="loginTest"/>
                </methods>
            </class>    
        </classes>
    </test>
    <test name="Login Tests two">
        <parameter name="two"/>
        <classes>
            <class name="test.java.Login">
                <methods>
                    <include name="loginTest"/>
                </methods>
            </class>                        
        </classes>
    </test>
</suite>
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Parameter
  • Low reputation (1):
Posted by: Vadim Zubovich