mgoodnow
mgoodnow

Reputation: 43

TestNG - How to get current class name from BeforeClass

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

Upvotes: 4

Views: 10076

Answers (2)

artdanil
artdanil

Reputation: 5082

Following should do the trick:

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

Upvotes: 18

Cedric Beust
Cedric Beust

Reputation: 15608

How about getClass()?

(a few more characters to keep SO happy)

Upvotes: 2

Related Questions