-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cartesian product for data providers #865
base: master
Are you sure you want to change the base?
Conversation
I think the overall idea can be useful but I'm not a fan of wiring it into the data provider engine since this can be done with straight Java by just combining the data providers manually and making that your data provider. In other words, I think this could just be a helper method. Thoughts? |
It certainly could be a helper method (that's what I'm currently doing in On 11 November 2015 at 18:10, Cedric Beust [email protected] wrote:
|
Another problem I have is that the syntax you chose to add (which is clever by the way, allowing multiple data provider names) can be interpreted in many ways. You chose to make it mean "cartesian product" but what if people just want to concatenate these results, for example? It doesn't seem wise to hardcode how these multiple data providers are handled this way. |
Yes, that occurred to me too - I could create an enum On 11 November 2015 at 20:23, Cedric Beust [email protected] wrote:
|
An enum still restricts what can be done, and you need to implement all these strategies in TestNG, whether they ever get used or not. All this points toward letting developers handle this themselves :) |
And why not having a Something like:
|
@cbeust I've done this in a whole different helper class I've called TestcaseGenerator @DataProvider(name="whUpgradeNewUserDataProvider")
public static Object[][] whUpgradeNewUserDataProvider() {
TestcaseGenerator tg = new TestcaseGenerator();
tg.add(new IRunnableMethod() {
@Override
public Object run() {
return WhUserBuilder.aRandomUser().build();
}
});
tg.add("netbilling"); // gateway
tg.add(System.currentTimeMillis()/1000 + 1000*60*60*24*365); // expiry
tg.add("month"); // plan
tg.add("descriptor_test", ""); // descriptor
tg.add("support_site_test", ""); // support_site
tg.add("555-111-222", ""); // support_phone
return tg.generate();
} Also I'm planning to add Java 8 support so that "IRunnableMethod" would be way less verbose (using Callable functional interface + lambda expressions). Would you prefer that approach? You think it's useful to add that to TestNG? Current methods on TestcaseGenerator are: |
@ricardf-cmp TestNG needs to remain Java 1.7 compatible so no, we can't use lambdas or functional interfaces yet. |
@cbeust Maybe I did not use the right words. What I meant was I'm using this code in Java 1.7. Let me put a clearer example: @DataProvider(name="sampleProvider")
public static Object[][] sampleProvider() {
TestcaseGenerator tg = new TestcaseGenerator();
tg.add(new IRunnableMethod() {
@Override
public Object run() {
return UserBuilder.aRandomUser().build();
}
});
tg.add("normal String", "$%&", ""); // string example
tg.addOptional(-1,0,1,99999); // optional numeric example
return tg.generate();
}
This is my last attempt :) If you don't like the idea then it's fine, for me it's been really helpful to stop thinking about test cases and just generate them all. If you think it's a good idea I'll create a PR for that. |
I think there are too many use cases to cover to justify adding this to TestNG, so I'd rather keep this out of the core. |
It'll be of more utility and lesser test cases for testng. If foo(dp...) is exposed. |
@mrpotes it would probably be cleaner to break up the cases you mentioned into separate annotations and keeping the current DataProvider annotation as the "simple" data provider. With an enum, all strategies would need to be implemented at once as @cbeust suggests but separate annotations could be implemented at your leisure. Thoughts? I'm thinking about moving forward with this. |
This would be useful. At the very least baking in some methods to merge DataProviders would be convenient even if you didn't want to provide a full grammar for merging them in any possible way. Needing to include methods for the Cartesian product of Object[][] in every project is kind of gross and this would be a natural place for them to live. |
Taking some inspiration from this post on the forums, this change adds support for an array of data provider strings in the Test annotation.