ITestResult listener - getName() issue

576 views
Skip to first unread message

sarthak Dayanand

unread,
Jan 20, 2012, 12:18:40 PM1/20/12
to testng...@googlegroups.com
Hi, 

I am using listener ITestResult in TestNG. 

When I call the method 
fileName = result.getName(); 

I get the result as "testLebara on instance 
null(com.example.tests.LebaraTest)" 

Where testLebara is my method name. Just want to know what does "on 
instance null" mean here. Can we remove it somehow? 

Thanks, 
Sarthak

Krishnan

unread,
Jan 22, 2012, 9:39:05 PM1/22/12
to testng...@googlegroups.com
Have your TestClass implement ITest interface, and implement the getTestName() interface and you should see the null going away.
Incase you dont want any name to be associated with your instance, you can choose to have getTestName() return back "".

sarthak Dayanand

unread,
Jan 23, 2012, 5:50:57 AM1/23/12
to testng-users
Thanks Kirshnan,

I tried doing that. My requirement is that I want just the methodName
to be returned. It should not be followed by "on instance null"
If I override getTestName() then result.getName() will return the name
set there.

Is there anyway to get just the methodName? (without the instance
name)

Thanks,
Sarthak

Aparna Jadhav

unread,
Dec 29, 2016, 9:14:03 AM12/29/16
to testng-users, sarth...@gmail.com
Hi,

I could solve this problem using below code:


public void onTestSuccess(ITestResult result) {
ITestNGMethod method = result.getMethod();
String message = "Test Execution is Successful:"+method.getMethodName();
try {
logInListener(result, Level.INFO, message);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Hope it will help
Reply all
Reply to author
Forward
0 new messages