简体   繁体   中英

TestNG :: How to get TestSuite name inside a TestMethod?

I have a scenario where many test suites are added to TestNG object for running. I have a testMethod() in a class TestClass. I am using dataProvider also.

I want to know inside the test method which is the current TestSuite ??

How can I achieve without disturbing my DataProvider parameters for the TestMethod ??

Here is the way Cedric implemented it after much convincing as you can see in this thread from a long time ago:

  @DataProvider(name = "A")
  protected Object[][] dp(ITestContext tc) {
    return new Object[][] { 
        { tc }
    };
  }

  @Test(dataProvider = "A")
  public void testA(ITestContext tc) {
    System.out.println("SUITE NAME:" + tc.getSuite().getXmlSuite().getName());
  }

Got the Answer.

From the book by Beust I got my answer.

There are different ways to define a dataProvider method:

@DataProvider
public void create() { ... }
@DataProvider
public void create(Method method) { ... }
@DataProvider
public void create(ITestContext context) { ... }
@DataProvider
public void create(Method method, ITestContext context) { ... }

And the last method helped me solve my problem. This method gives the method reference that is going to be called as well as the Test Context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM