Quantcast

BeforeMethod params injected from dataProvider : BUG

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

BeforeMethod params injected from dataProvider : BUG

Ben Mark
Hi Cedric,

When passing a POJO from the dataProvider to a @Test/BeforeMethod, there's a runtime bug in the BeforeMethod which can be seen while debugging.
The test gets that POJO but the BeforeMethod gets something weird, it gets a 2d array containing  1 row with that pojo..
The BeforeMethod accepts only Object [] array, and there is no way of reaching that injected pojo from the dataProvider.

Will be glad to post a mock project with a debug screenshot

A fix could help me and others alot

Thanks in advance Cedric
~Ben

--
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
|  
Report Content as Inappropriate

Re: BeforeMethod params injected from dataProvider : BUG

⇜Krishnan Mahadevan⇝

Ben

BeforeMethod is designed to receive the parameters that a @Test method would get in the form of a Object[] array wherein Object[0] represents the first parameter and so on and so forth.

Can you please elaborate as to what is the error you are seeing ? Source code and stack trace of the problem would be a great help.


On Mon, Feb 6, 2017, 17:03 Ben Mark <[hidden email]> wrote:
Hi Cedric,

When passing a POJO from the dataProvider to a @Test/BeforeMethod, there's a runtime bug in the BeforeMethod which can be seen while debugging.
The test gets that POJO but the BeforeMethod gets something weird, it gets a 2d array containing  1 row with that pojo..
The BeforeMethod accepts only Object [] array, and there is no way of reaching that injected pojo from the dataProvider.

Will be glad to post a mock project with a debug screenshot

A fix could help me and others alot

Thanks in advance Cedric
~Ben

--
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.
--

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/

--
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
|  
Report Content as Inappropriate

Re: BeforeMethod params injected from dataProvider : BUG

Ben Mark
In reply to this post by Ben Mark
Yes of-course krishnan,

The following code emphasizes the problem 
  • The pojo is passed from the dataProvider to both @Test and @BeforeTest, only @Test waits until @BeforeMethod is done
  • The Problem: in compile time BeforeMethod signature's has 1 argument --> 1d array , where in runtime, it is a 2d array from this conflict , you're unable (ASFAIK) to reach the object


BeforeMethodBug.java

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class BeforeMethodBug {
@BeforeMethod
public void init(Object [] params){
//in runtime params is a 2d array, in compile time it is a 1d array, kind of a conflict..
System.out.println(params[0]);
for (int i = 0; i < params.length; i++) {
System.out.println(params[i].toString());
}
}
@DataProvider(name="dp")
public Object[][] dataProviderMethod(){
return new Object[][] {
              { new Pojo("TestCase1")},
              { new Pojo("TestCase2")}};
}
@Test(dataProvider="dp")
public void TestMethod1(Pojo pojo){
System.out.println("TestMethod1 pojo name:" +pojo.name);
}
class Pojo{
private String name;
public Pojo(String name){
this.name=name;
}
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
}



On Monday, 6 February 2017 13:33:42 UTC+2, Ben Mark wrote:
Hi Cedric,

When passing a POJO from the dataProvider to a @Test/BeforeMethod, there's a runtime bug in the BeforeMethod which can be seen while debugging.
The test gets that POJO but the BeforeMethod gets something weird, it gets a 2d array containing  1 row with that pojo..
The BeforeMethod accepts only Object [] array, and there is no way of reaching that injected pojo from the dataProvider.

Will be glad to post a mock project with a debug screenshot

A fix could help me and others alot

Thanks in advance Cedric
~Ben

--
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
|  
Report Content as Inappropriate

Re: BeforeMethod params injected from dataProvider : BUG

Ben Mark
In reply to this post by Ben Mark



On Monday, 6 February 2017 13:33:42 UTC+2, Ben Mark wrote:
Hi Cedric,

When passing a POJO from the dataProvider to a @Test/BeforeMethod, there's a runtime bug in the BeforeMethod which can be seen while debugging.
The test gets that POJO but the BeforeMethod gets something weird, it gets a 2d array containing  1 row with that pojo..
The BeforeMethod accepts only Object [] array, and there is no way of reaching that injected pojo from the dataProvider.

Will be glad to post a mock project with a debug screenshot

A fix could help me and others alot

Thanks in advance Cedric
~Ben

--
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
|  
Report Content as Inappropriate

Re: BeforeMethod params injected from dataProvider : BUG

Ben Mark
In reply to this post by Ben Mark
Can @BeforeMethod  signature overload include Object next to Object [] ?

On Monday, 6 February 2017 13:33:42 UTC+2, Ben Mark wrote:
Hi Cedric,

When passing a POJO from the dataProvider to a @Test/BeforeMethod, there's a runtime bug in the BeforeMethod which can be seen while debugging.
The test gets that POJO but the BeforeMethod gets something weird, it gets a 2d array containing  1 row with that pojo..
The BeforeMethod accepts only Object [] array, and there is no way of reaching that injected pojo from the dataProvider.

Will be glad to post a mock project with a debug screenshot

A fix could help me and others alot

Thanks in advance Cedric
~Ben

--
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
|  
Report Content as Inappropriate

Re: BeforeMethod params injected from dataProvider : BUG

Julien Herr
What I see on your screenshot is:
"params is an array with 1 value"
"the first value is Pojo"
"the name attribute of the first Pojo is TestCase1"

=> I think everything is working as expected.

And I'm pretty sure the following will work:
System.out.println(((Pojo)params[0]).name);

Le mardi 7 février 2017 13:26:47 UTC+1, Ben Mark a écrit :
Can @BeforeMethod  signature overload include Object next to Object [] ?

On Monday, 6 February 2017 13:33:42 UTC+2, Ben Mark wrote:
Hi Cedric,

When passing a POJO from the dataProvider to a @Test/BeforeMethod, there's a runtime bug in the BeforeMethod which can be seen while debugging.
The test gets that POJO but the BeforeMethod gets something weird, it gets a 2d array containing  1 row with that pojo..
The BeforeMethod accepts only Object [] array, and there is no way of reaching that injected pojo from the dataProvider.

Will be glad to post a mock project with a debug screenshot

A fix could help me and others alot

Thanks in advance Cedric
~Ben

--
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
|  
Report Content as Inappropriate

Re: BeforeMethod params injected from dataProvider : BUG

Ben Mark
In reply to this post by Ben Mark
Thanks for your reply Julien,  what you see in the screen-shot

is params[1] <-- 1d array with 1 value

& that value is another array, meaning it's nested inside.

If there's a way of grabbing that value I'm down to it.




~Ben

On Monday, 6 February 2017 13:33:42 UTC+2, Ben Mark wrote:
Hi Cedric,

When passing a POJO from the dataProvider to a @Test/BeforeMethod, there's a runtime bug in the BeforeMethod which can be seen while debugging.
The test gets that POJO but the BeforeMethod gets something weird, it gets a 2d array containing  1 row with that pojo..
The BeforeMethod accepts only Object [] array, and there is no way of reaching that injected pojo from the dataProvider.

Will be glad to post a mock project with a debug screenshot

A fix could help me and others alot

Thanks in advance Cedric
~Ben

--
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
|  
Report Content as Inappropriate

Re: BeforeMethod params injected from dataProvider : BUG

Ben Mark
In reply to this post by Ben Mark
I was wrong, it isn't any bug
Could reach the object by a simple cast

@BeforeMethod
public void init(Object [] params){
String Pojo = ((Pojo)params[0]).name;
}

Sorry for the trouble

cheers


On Monday, 6 February 2017 13:33:42 UTC+2, Ben Mark wrote:
Hi Cedric,

When passing a POJO from the dataProvider to a @Test/BeforeMethod, there's a runtime bug in the BeforeMethod which can be seen while debugging.
The test gets that POJO but the BeforeMethod gets something weird, it gets a 2d array containing  1 row with that pojo..
The BeforeMethod accepts only Object [] array, and there is no way of reaching that injected pojo from the dataProvider.

Will be glad to post a mock project with a debug screenshot

A fix could help me and others alot

Thanks in advance Cedric
~Ben

--
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.
Loading...