Feature proposal regarding data providers

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Feature proposal regarding data providers

Harmin Parra Rueda
Hello,

I would like to propose a new feature for the TestNG framework :

Proposition : Allow users to define the data provider in the xml file

This has the advantage that you can run the same test in different suites with different data providers.

This is an idea of how I see this feature into action

//A data provider method
public static Object[][] myDataProvider() {...}

//A test
@Test(dataProviderMethod = "myData")
public void test(...) {...}

//a suite xml file
<suite name="My suite1">
  <dataProviderMethod name="myData" method="mypackage.myDataProvider"/>
  <test name="My test">
  ...
</suite>

//another suite xml file
<suite name="My suite2">
  <dataProviderMethod name="myData" method="mypackage.anotherDataProvider"/>
  <test name="My test">
  ...
</suite>

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Feature proposal regarding data providers

⇜Krishnan Mahadevan⇝
You should still be able to do that today, using an annotation transformer implementation as a listener. Please see below for sample and suite xml.

public class ChangingDataProviders {

@Test
public void testMethod(int a) {
System.err.println("Number " + a);
}

@DataProvider (name = "dp1")
public Object[][] getData1() {
return new Object[][] {
{1}, {2}
};
}

@DataProvider (name = "dp2")
public Object[][] getData2() {
return new Object[][] {
{100},
{200}
};
}

public static class DPTransformer implements IAnnotationTransformer {

@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,
Method testMethod) {
annotation.setDataProvider("dp2");

}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Class2Suite" parallel="false">
<listeners>
<listener class-name="organized.chaos.testng.ChangingDataProviders$DPTransformer"/>
</listeners>
<test name="Class2Test">
<classes>
<class name="organized.chaos.testng.ChangingDataProviders"/>
</classes>
</test> <!-- Class1Test -->
</suite> <!-- Class1Suite -->

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/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On 17-Dec-2015, at 4:48 PM, Harmin Parra Rueda <[hidden email]> wrote:

Hello,

I would like to propose a new feature for the TestNG framework :

Proposition : Allow users to define the data provider in the xml file

This has the advantage that you can run the same test in different suites with different data providers.

This is an idea of how I see this feature into action

//A data provider method
public static Object[][] myDataProvider() {...}

//A test
@Test(dataProviderMethod = "myData")
public void test(...) {...}

//a suite xml file
<suite name="My suite1">
  <dataProviderMethod name="myData" method="mypackage.myDataProvider"/>
  <test name="My test">
  ...
</suite>

//another suite xml file
<suite name="My suite2">
  <dataProviderMethod name="myData" method="mypackage.anotherDataProvider"/>
  <test name="My test">
  ...
</suite>


--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Feature proposal regarding data providers

Harmin Parra Rueda
In reply to this post by Harmin Parra Rueda
Thank you Krishnan.

This was exactly what I was looking for : the possibility to change the data provider in each suite.

Thanks :)

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Feature proposal regarding data providers

Panikera
Hi Krishnan,

I am using above source code(same class, same methods and same xml also) to change dataproviders at runtime. But I'm getting below exception. 

org.testng.TestNGException: 
Method testMethod requires 1 parameters but 0 were supplied in the @Test annotation.
at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:198)
at org.testng.internal.Parameters.createParameters(Parameters.java:134)
at org.testng.internal.Parameters.createParameters(Parameters.java:373)
at org.testng.internal.Parameters.handleParameters(Parameters.java:450)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1383)
at org.testng.internal.Invoker.createParameters(Invoker.java:1075)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1180)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


Krishnan,
Please let me know where I am doing wrong.

Thanks in advance

Regards,
Panikera

On Fri, Dec 18, 2015 at 5:03 PM, Harmin Parra Rueda <[hidden email]> wrote:
Thank you Krishnan.

This was exactly what I was looking for : the possibility to change the data provider in each suite.

Thanks :)

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Feature proposal regarding data providers

⇜Krishnan Mahadevan⇝
Not sure what could be wrong. But it looks like the listener wasn't being invoked at all. That can be the only reason behind why that can happen. Please check at your end.

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/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Sun, Jan 3, 2016 at 9:04 AM, Panikera Raj <[hidden email]> wrote:
Hi Krishnan,

I am using above source code(same class, same methods and same xml also) to change dataproviders at runtime. But I'm getting below exception. 

org.testng.TestNGException: 
Method testMethod requires 1 parameters but 0 were supplied in the @Test annotation.
at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:198)
at org.testng.internal.Parameters.createParameters(Parameters.java:134)
at org.testng.internal.Parameters.createParameters(Parameters.java:373)
at org.testng.internal.Parameters.handleParameters(Parameters.java:450)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1383)
at org.testng.internal.Invoker.createParameters(Invoker.java:1075)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1180)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


Krishnan,
Please let me know where I am doing wrong.

Thanks in advance

Regards,
Panikera

On Fri, Dec 18, 2015 at 5:03 PM, Harmin Parra Rueda <[hidden email]> wrote:
Thank you Krishnan.

This was exactly what I was looking for : the possibility to change the data provider in each suite.

Thanks :)

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Feature proposal regarding data providers

Mark Derricutt
In reply to this post by Panikera
On 3 Jan 2016, at 16:34, Panikera Raj wrote:

> org.testng.TestNGException: 
> Method testMethod requires 1 parameters but 0 were supplied in the @Test annotation.
> at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:198)


this is saying that testMethod takes an argument, but TestNG could not resolve any @Test(parameters="") value, or @Paramaters.

I assume it's falling into that code due to not finding a data provider?


--
Mark Derricutt
http://www.theoryinpractice.net
http://www.chaliceofblood.net
http://plus.google.com/+MarkDerricutt
http://twitter.com/talios
http://facebook.com/mderricutt

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

signature.asc (494 bytes) Download Attachment