0

I wonder if it's possible to grab the java method name in runtime? I've tried this code already:

String name = new Object(){}.getClass().getEnclosingMethod().getName();

But it returns the last java method I ran, and I need to get the @Test someTest() {} method name

0xh3xa
  • 4,801
  • 2
  • 14
  • 28
Dimencion Rider
  • 145
  • 1
  • 4
  • 13
  • Did you see this answer: https://stackoverflow.com/questions/2952202/how-do-i-get-the-name-of-the-test-method-that-was-run-in-a-testng-tear-down-meth – 0xh3xa Mar 24 '20 at 15:30
  • Yes, I did. I saw it. But this will work only if you want to get the method name after the test is completed (teardown). In my case, I would need to know how to get it during test execution in runtime. – Dimencion Rider Mar 24 '20 at 15:49
  • You want to get the current method name which is running at testing, right? – 0xh3xa Mar 24 '20 at 15:52
  • Yes, that is correct. – Dimencion Rider Mar 24 '20 at 15:58
  • And this answer: https://stackoverflow.com/questions/14921880/is-it-a-way-to-get-the-test-method-name-within-testng-listeners-on-configuration – 0xh3xa Mar 24 '20 at 15:59
  • Do you have `methodName = new Object() {}.getClass().getEnclosingMethod().getName();` as first line one code in your @Test method? – supputuri Mar 24 '20 at 16:37

0 Answers0