0

Inside TestNG test method, I am using this.getClass().getEnclosingMethod().getName() to get the current method name but it gives failure exception as java.lang.NullPointerException

I am unsure, what would be the problem?

Assert.assertEquals(this.getClass().getEnclosingMethod().getName(), testcaseName);
Soni K
  • 156
  • 2
  • 6
  • 19
  • This doesn't seem to be duplicate, i am calling getClass methods on the class itself,so not sure why it's throwing the exception. I'll have a look at the link though. – Soni K May 27 '19 at 21:52
  • 1
    It's pretty similar, in your example `getEnclosingMethod()` is `null` so `getName()`throws the exception. – Paul Lemarchand May 27 '19 at 21:58
  • I've added @BeforeMethod public void beforeTestMethod(Method testMethod){ log4j.info("Before Testmethod: " + testMethod.getName()); testName = testMethod.getName(); } This fixed the problem. – Soni K May 28 '19 at 23:30

0 Answers0