How to get the name of the test in @beforeTest method

492 views
Skip to first unread message

Nainappa Illi

unread,
Apr 20, 2017, 7:16:10 PM4/20/17
to testng-users
Hi,

My sample Testng.xml is:

<suite name="SampleSuite">
     <test name="SampleTest">
        <classes>
            <class name="class1"/>
            <class name="class2"/>
        </classes>
    </test>
</suite>

In my @beforeTest method, I need either the <test> name or <class> name. How can I get that?

Thanks in Advance.

Nainappa Illi

unread,
Apr 21, 2017, 12:25:51 PM4/21/17
to testng-users
Got the answer. We should be using ITestContext as the parameter for beforetest method. Something as below.

 @BeforeTest(alwaysRun = true)
  public void setup(ITestContext context) throws Exception {
    String className = getClass().getSimpleName();
  }
Reply all
Reply to author
Forward
0 new messages