different test description for the data provider

594 views
Skip to first unread message

Ankit S.

unread,
Aug 5, 2013, 5:37:30 PM8/5/13
to testng...@googlegroups.com
I want to run same test with a @DataProvider. But for each data provider run I would like to update the test description. 

I know I could make 2 different data providers and 2 different test case. But that fix will not work for me as I have many entry in the data provider and don't want to make test for each of them. I just want to have different test description for them.

thanks,

ankit


import static org.testng.Assert.assertTrue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.intuit.ctodev.qa.dis.library.util.DataProviderLevel;

public class SampleTest
{
    @Test(groups = { "dptest"}, dataProvider = "dptest")
    public void SampleTest1(String testName)
    {
        System.out.println("\n\nStart sample test - 1 - " + testName);
        assertTrue(true, "test FAILED because of value is not as expected.");
    }
   
    @DataProvider(name = "dptest")
    public Object[][] dptest()
    {
        return new Object[][]
        {
                { "test1"}, //test description: testing test1
                { "test2"}, //test description: testing test2
        };
    }
}

Krishnan Mahadevan

unread,
Aug 6, 2013, 2:50:01 AM8/6/13
to testng...@googlegroups.com
When you say test description, can you please help elaborate as to what exactly are you hinting at ?

If you are referring to the description attribute of @Test annotation, then the answer is NO, you cannot use a @DataProvider to change this to the best of my knowledge.

@DataProvider basically helps you run a test method n times and doesnt help you alter the attributes of a @Test annotated test method

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/




--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, 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/groups/opt_out.
 
 

Ankit S.

unread,
Aug 15, 2013, 12:24:44 AM8/15/13
to testng...@googlegroups.com

Yes I am talking about the @Test annotation.

The reason why I would run the @DataProvider is to run a test method n time. Right. But each time I run it the @DataProvider value is different. So its testing something different. In my case they are different test cases.

thanks,

ankit

Ankit Mundra

unread,
Aug 15, 2013, 5:52:09 AM8/15/13
to testng...@googlegroups.com
Hi

Not sure but you can try using the annotation transformer I.e. implementing the IAnnotationTransformer class. That might help!

Thanks
Ankit

Krishnan Mahadevan

unread,
Aug 16, 2013, 3:36:10 AM8/16/13
to testng...@googlegroups.com
If its about being able to distinguish different iterations then I will suggest that you please take a look at this blog post of mine :



Annotation transformer works only once and won't get executed for every iteration of the data provider. 
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, 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/groups/opt_out.


--
Reply all
Reply to author
Forward
0 new messages