New listener result.getTestName() is null

704 views
Skip to first unread message

testnguser

unread,
Jul 24, 2012, 12:45:26 PM7/24/12
to testng...@googlegroups.com

I have  a listener extending TestListenerAdapter. Functions such as getMethod etc. work perfectly. But getTestName() shows null. My TestNGSuite.xml file specifies
<suite ....>
<test name="hellotest" ....>



//listener class
public void onTestFailure(ITestResult result) {
       
        System.out.println("Test Name :: "+result.getTestName());
       
    }

Am I specifying it wrong?


Thanks!

Krishnan Mahadevan

unread,
Jul 24, 2012, 12:58:42 PM7/24/12
to testng...@googlegroups.com
Harini,
getTestName() returns the value that you configure your Testclass to implement ITest interface and then have it return the desired test name.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"




--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/RNK_92JwB2kJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Krishnan Mahadevan

unread,
Jul 24, 2012, 1:00:28 PM7/24/12
to testng...@googlegroups.com
Javadocs : http://testng.org/javadoc/org/testng/ITestResult.html#getTestName%28%29


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



testnguser

unread,
Jul 24, 2012, 2:38:25 PM7/24/12
to testng...@googlegroups.com
Hello,

Thanks a lot for the tip. :) It works if I set the testName.
My bad, I did not notice the documentation. Is there a way I can receive the testName from my suite.xml file?
Thanks!
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com.

Krishnan Mahadevan

unread,
Jul 24, 2012, 2:41:37 PM7/24/12
to testng...@googlegroups.com
You could try passing it via @Parameters and then have the @Test method set the value for the test name in a data member of your test class which can be returned back by the ITest interface method. 

Would that help?
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/lOoWC_f_KI4J.

To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

testnguser

unread,
Jul 24, 2012, 2:43:41 PM7/24/12
to testng...@googlegroups.com
I thought of that. I was wondering if a class/interface already does that. 
Thanks, Anyways! :)

Krishnan Mahadevan

unread,
Jul 24, 2012, 2:45:31 PM7/24/12
to testng...@googlegroups.com
Am not aware of anything out there that could already do this for you in TestNG. . 
This was something that came up at the top of my head and on the fly :)
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/E-1GqZg4IjgJ.

To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Neeraja

unread,
Aug 29, 2012, 7:52:37 AM8/29/12
to testng...@googlegroups.com


Krishnan Mahadevan <krishnan.mahadevan1978@...> writes:

>
>
> You could try passing it via <at> Parameters and then have the <at> Test
method set the value for the test name in a data member of your test class which
can be returned back by the ITest interface method. 
>
> Would that help?On Wednesday, July 25, 2012, testnguser wrote:Hello,
> Thanks a lot for the tip. :) It works if I set the testName.
> My bad, I did not notice the documentation. Is there a way I can receive the
testName from my suite.xml file?
> Thanks!
>
> On Tuesday, July 24, 2012 10:00:28 AM UTC-7, Krishnan wrote:
> Javadocs : http://testng.org/javadoc/org/testng/ITestResult.html#getTestName%28%29
>
>
> Thanks & Regards
> Krishnan Mahadevan"All the desirable things in life are either illegal,
expensive, fattening or in love with someone else!"On Tue, Jul 24, 2012 at 10:28
PM, Krishnan Mahadevan <krishnan.mahadevan1978 <at> gmail.com>
wrote:Harini,getTestName() returns the value that you configure your Testclass
to implement ITest interface and then have it return the desired test name.
>
>
> https://groups.google.com/forum/#!topic/testng-users/y2ImcNn9AWY
>
>
> Thanks & RegardsKrishnan Mahadevan"All the desirable things in life are either
illegal, expensive, fattening or in love with someone else!"
> On Tue, Jul 24, 2012 at 10:15 PM, testnguser
<techie...@gmail.com> wrote:
>
> I have  a listener extending TestListenerAdapter. Functions such as getMethod
etc. work perfectly. But getTestName() shows null. My TestNGSuite.xml file
specifies <suite ....><test name="hellotest" ....>//listener classpublic void
onTestFailure(ITestResult result) {                System.out.println("Test Name
:: "+result.getTestName());            }Am I specifying it wrong?Thanks!
>


Hi Krishnan,

i have tried the same but for the first set of data i am getting the name as
"defaultTestName" and second set of data i am getting testcase name from first
set of dataprovider data.

can you please share some code how you have done.

here is the sample code snippet how i did. I want the first parameter of the
dataprovider to be set as testcase name in the report.

public class AuditIntegrationTest implements ITest{
private String name;


public AuditIntegrationTest(String name) {
this.name = name;
}
@Test(groups = { "Smoke", "Positive","Regression","example"}, dataProvider =
"sampleProvider")
public void testSampleTestcase(String testCase,
String testDesc) throws Exception {
//ITestAnnotation.setTestName(testDesc);
this.name=testCase;
assertNotNull(testDesc);

}


@DataProvider(name = "sampleProvider")
public static Object[][] getSampleProvider() {
Object[][] retObjArr = new Object[][] {
{"Testcase1", "sample1"},
{"Testcase2", "sample2"},
{"Testcase3", "sample3"},

};

return (retObjArr);
}

@Override
public String getTestName() {
// TODO Auto-generated method stub
return name;
}

}

Thanks in advance,
Neeraja



Reply all
Reply to author
Forward
0 new messages