TestNG - How to get current class name from BeforeClass

java, testng

Solution

Following should do the trick:

@BeforeClass
public void beforeClass() {
    String className = this.getClass().getName();
}

Problem

TestNG - How to get current class name from BeforeClass. I have class A with extends class B ``` class B { @BeforeClass public void beforeClass() { /* Need test class name 'A' */ } } class A extends B { @Test public void test() { /* do something */ } } ``` In BeforeClass I have tried the only two parameters which inject: ITestContext and XmlTest. However, no luck in determining how to get the class name from either. Anyone got any ideas? Thanks

Original source