Can somebody give me simple example to override test name at run time ?

923 views
Skip to first unread message

Sonu

unread,
May 12, 2014, 7:49:28 AM5/12/14
to testng...@googlegroups.com
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}
Message has been deleted

ajourney

unread,
May 13, 2014, 11:31:25 AM5/13/14
to testng...@googlegroups.com
What is your expected output with this code?
When do you want to see the name of your test changed? 
if thats the case you woiuldn't want to have the setTestName called in the AfterMethod that would be after the test is over.

djangofan

unread,
May 13, 2014, 11:39:32 AM5/13/14
to testng...@googlegroups.com
Yes, I created a project that does that here:  http://djangofan.github.io/testng-custom-report-example/
-Jon

Ramshankar Behera

unread,
May 13, 2014, 11:59:45 PM5/13/14
to testng...@googlegroups.com

After each test execution I want to change the method name for the reporting purpose. Can you please tell me the example?

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Ramshankar Behera

unread,
May 14, 2014, 2:54:53 AM5/14/14
to testng...@googlegroups.com
Hi Jon,

Thanks for your reply on my question.

I tried to implement your project but in the default report I don't see the change name. Please find the attachment.

Thanks,
Ram.


--
testNg.PNG

djangofan

unread,
Jul 6, 2014, 12:27:04 PM7/6/14
to testng...@googlegroups.com
That is because it changes the name while the test is running and so the name change doesn't show up in the Eclipse integration.  You need to open the HTML report in the  target directory to see the changed name.    Since I created that project I think I know how to change the name displayed in the Eclipse integration but I haven't tried it yet.  Basically, in the @BeforeMethod, pass a Object[] that contains the test name and then apply the name change within that before method.  Haven't tried it yet, but wanted to let you know what I was thinking.
-Jon

djangofan

unread,
Jul 30, 2014, 11:05:47 AM7/30/14
to testng...@googlegroups.com
Just wanted to update everyone that my "custom report" example that I linked to on this thread works fine as long as you don't use a data provider.  When you get a data provider involved, then the class instance is shared between multiple runs and the TestNG report shows the same name for all runs of that test.   Still haven't solved that problem but hopefully I will someday.
-Jon
Reply all
Reply to author
Forward
0 new messages