Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Adding support for cartesian dataproviders
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Derricutt  
View profile  
 More options Aug 7 2012, 12:00 am
From: Mark Derricutt <m...@talios.com>
Date: Tue, 7 Aug 2012 16:00:04 +1200
Local: Tues, Aug 7 2012 12:00 am
Subject: Adding support for cartesian dataproviders
Cedric,

I was just updating some tests and came up with a pattern that I was thinking would be good to include in TestNG directly. The concept is a simple cartesian product support for data providers.

In my test I know have three providers, the first two providing discreet sets of data, with their concerns separated out, the third being the cartesian procut:

    @DataProvider
    public Object[][] provideBillingReferences() {
        return new Object[][] {...};
    }

    @DataProvider
    public Object[][] provideSplitData() {
        return new Object[][] {...};
    }

    @DataProvider
    public Iterator<Object[]> provideMergedSplitData() {
        return DataProviderUtil.cartesianProviderFrom(ImmutableList.of(provideSplitData(), provideBillingReferences()));
    }

    @Test(dataProvider = "provideMergedSplitData")
    ….

What I was thinking was this could be handy to incorporate directly into TestNG then I could do something

    @Test(dataProvider = {"provideBillingReferences", "provideSplitData"})

and have TestNG handle the cartesian itself. Thoughts?

My current implementation of this uses Google Guava:

public class DataProviderUtil {

    /**
     * Given a list of @DataProvider results, generate a cartesian product of available combinations.
     * @param dataProviderData A list of @DataProvider results
     * @return The cartesian product of available combinations.
     */
    public static Iterator<Object[]> cartesianProviderFrom(List<Object[][]> dataProviderData) {

        ImmutableList.Builder<Set<Object[]>> cartesianSets = ImmutableList.builder();
        for (Object[][] objects : dataProviderData) {
            cartesianSets.add(Sets.newHashSet(objects));
        }

        Set<List<Object[]>> cartesianData = Sets.cartesianProduct(cartesianSets.build());
        List<Object[]> data = Lists.newArrayList();

        for (List<Object[]> objects : cartesianData) {
            Object[] mergedArray = flattenObjectArray(objects);
            data.add(mergedArray);
        }

        return data.iterator();
    }

    private static Object[] flattenObjectArray(List<Object[]> arrays) {

        int len = 0;
        for (Object[] array : arrays) {
            len += array.length;
        }

        int index = 0;

        Object[] mergedArray = new Object[len];

        for (Object[] array : arrays) {
            for (int i = 0; i < array.length; i++) {
                mergedArray[index++] = array[i];
            }
        }

        return mergedArray;
    }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cédric Beust ♔  
View profile  
 More options Aug 7 2012, 12:04 am
From: Cédric Beust ♔ <ced...@beust.com>
Date: Mon, 6 Aug 2012 21:04:42 -0700
Local: Tues, Aug 7 2012 12:04 am
Subject: Re: [testng-dev] Adding support for cartesian dataproviders

Hey Mark,

Happy to add your DataProviderUtils class to TestNG, mind sending me a pull
request?

--
Cédric


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Derricutt  
View profile  
 More options Aug 7 2012, 5:26 am
From: Mark Derricutt <m...@talios.com>
Date: Tue, 7 Aug 2012 21:26:26 +1200
Local: Tues, Aug 7 2012 5:26 am
Subject: Re: [testng-dev] Adding support for cartesian dataproviders
I'll try and clean it up and remove the Guava dependency ( I'm not sure if TestNG currently have any Guava dependencies at all? I don't think it does ).

Currently it feels a little... wrong to add the class/dependency for just one method so I may hold off for now.

On 7/08/2012, at 4:04 PM, Cédric Beust ♔ <ced...@beust.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cédric Beust ♔  
View profile  
 More options Aug 7 2012, 7:43 am
From: Cédric Beust ♔ <ced...@beust.com>
Date: Tue, 7 Aug 2012 04:43:33 -0700
Local: Tues, Aug 7 2012 7:43 am
Subject: Re: [testng-dev] Adding support for cartesian dataproviders

Indeed, I had to remove the Guava (and Guice) dependency from TestNG
because it was close to impossible to have those and still produce a jar
file that works for both ant and maven.

--
Cédric


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Karel Rank  
View profile  
 More options Sep 17 2012, 5:34 am
From: Karel Rank <karel.r...@gmail.com>
Date: Mon, 17 Sep 2012 02:34:07 -0700 (PDT)
Local: Mon, Sep 17 2012 5:34 am
Subject: Re: [testng-dev] Adding support for cartesian dataproviders

Any progress regarding combinations?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Derricutt  
View profile  
 More options Sep 17 2012, 6:27 pm
From: Mark Derricutt <m...@talios.com>
Date: Tue, 18 Sep 2012 10:27:21 +1200
Local: Mon, Sep 17 2012 6:27 pm
Subject: Re: [testng-dev] Adding support for cartesian dataproviders
To be honest I got sidetracked with other things to try and refactor it to not use Guava.

For now one could simply pull in the class to their own project.  ( Or I could extract it to an artifact and push it to maven central ).

If I get some time this week I'll see if I can rework it tho.

On 17/09/2012, at 9:34 PM, Karel Rank <karel.r...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roman Hiden  
View profile  
 More options Oct 5 2012, 4:31 pm
From: Roman Hiden <romeo8...@gmail.com>
Date: Fri, 5 Oct 2012 13:31:23 -0700 (PDT)
Local: Fri, Oct 5 2012 4:31 pm
Subject: Re: Adding support for cartesian dataproviders

Thanks that would be helpful at least for me. Instead of creating manually
all the combinations you could just rely on Cartesian provider


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »