Method not getting invoked within the test

7 views
Skip to first unread message

testng user

unread,
Dec 23, 2009, 2:24:27 PM12/23/09
to testng-users
Hello,

I have a test as below

@Test(groups="A"), dataProvider="myProvider")
public void testMyCode(MyData data) throws Exception
{
//Call another method from the test
boolean result=myMethod(List of parameters)

}

myMethod is not even called and I could see the below exception.

java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:
607)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:517)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:669)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:956)
at org.testng.internal.TestMethodWorker.invokeTestMethods
(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:
110)
at org.testng.TestRunner.runWorkers(TestRunner.java:759)
at org.testng.TestRunner.privateRun(TestRunner.java:592)
at org.testng.TestRunner.run(TestRunner.java:486)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:877)
at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
at org.testng.TestNG.run(TestNG.java:751)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)

What should I be doing to fix this issue?

Thanks.

Cédric Beust ♔

unread,
Dec 23, 2009, 4:09:38 PM12/23/09
to testng...@googlegroups.com
Hi,

Can you post your entire class (trimmed as much as possible) so I can try to reproduce this problem?

Thanks.

-- 
Cedric



--

You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.





--
Cédric


testng user

unread,
Dec 23, 2009, 4:30:53 PM12/23/09
to testng-users
Hello Cedric,

Pls. find the sample code.

Class MyTest

{

@Parameters ({ "a","b","c})
@BeforeSuite(groups= {"All"},alwaysRun=true)
public void setValues(String a, String b, String c)
{
this.a=a;
this.b=b;
this.c=c;
MyHelper obj=new MyHelper(a,b,c);
}

@BeforeGroups(groups={"A","B","C","D"} )
{
//Connect to the database and fetch values
}

@Test(groups="A"), dataProvider="myProvider")
public void testMyCode(MyData data) throws Exception
{
//Call another method from the test

boolean result=obj.myMethod(data.getA(), data.getB(),
data.getC());


}

@AfterGroups(groups={"A","B","C","D"} )
{
//Start and stop multiple servers.
}

@DataProvider(name="myProvider")
public Iterator getData()
{
return new MyIterator("A");
}

A) I figured out that the MyHelper obj is "NULL" when called in the
tests. But in the before suite it is created. Not sure why it is NULL
in the test method. I am not sure by resolving the issue we can get
rid of the exception I posted above.

I would greatly appreciate if we have more clear documentation in
testng.org site for different configuration methods (with examples).
Most of the issues I faced regarding the usage of BeforeGroups
annotation is faced by lot of other members in the group. I got
solutions reading the posts in the group but felt that having a good
documentation would greatly help everyone.

Thanks !!

> > testng-users...@googlegroups.com<testng-users%2Bunsubscribe@google­groups.com>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.
>
> --

> ***Cédric
> *- Hide quoted text -
>
> - Show quoted text -

testng user

unread,
Dec 23, 2009, 4:45:55 PM12/23/09
to testng-users
Hello Cedric,

From the test output I noticed that BeforeSuite and BeforeGroups
method are called at the same time and hence the BeforeGroups method
could not get the values of configuration parameters passed from
testng.xml file in the BeforeSuite method.


Thanks.

> > - Show quoted text -- Hide quoted text -

Cédric Beust ♔

unread,
Dec 23, 2009, 5:02:27 PM12/23/09
to testng...@googlegroups.com
By the way, is this the only error you are seeing?  I'm guessing something else went wrong beforehand (such as TestNG not finding the data provider), so can you make sure there is no other error further up in the console?

-- 
Cedric


2009/12/23 Cédric Beust ♔ <cbe...@google.com>



--
Cédric


Cédric Beust ♔

unread,
Dec 23, 2009, 5:10:59 PM12/23/09
to testng...@googlegroups.com
On Wed, Dec 23, 2009 at 1:30 PM, testng user <gaay...@gmail.com> wrote:
Hello Cedric,

Pls. find the sample code.

Class MyTest

{

@Parameters ({ "a","b","c})
@BeforeSuite(groups= {"All"},alwaysRun=true)
public void setValues(String a, String b, String c)
{
  this.a=a;
  this.b=b;
  this.c=c;
  MyHelper obj=new MyHelper(a,b,c); 

You are creating a local variable here, are you sure you are not shadowing a field "obj", which therefore never gets initialized?

In other words, remove "MyHelper" in the line above and see if it fixes your problem.

--
Cédric


testng user

unread,
Dec 23, 2009, 5:12:52 PM12/23/09
to testng-users
Hello Cedric,

I see no issues in the dataprovider. The only issue I see now is the
values set in the setValues() method ( which are mostly parameters to
connect to DB and server and the session information) is not available
in the test method for some reason. I have multiple groups which
access the same information "A", "B","C" and "D".

I am surprised to see that the same configuration parameters are
available for group "B" which is called after group "A".

Thanks..

On Dec 23, 2:02 pm, Cédric Beust ♔ <cbe...@google.com> wrote:
> By the way, is this the only error you are seeing?  I'm guessing something
> else went wrong beforehand (such as TestNG not finding the data provider),
> so can you make sure there is no other error further up in the console?
>
> --
> Cedric
>
> 2009/12/23 Cédric Beust ♔ <cbe...@google.com>
>
>
>
>
>
> > Hi,
>
> > Can you post your entire class (trimmed as much as possible) so I can try
> > to reproduce this problem?
>
> > Thanks.
>
> > --
> > Cedric
>

> >> testng-users...@googlegroups.com<testng-users%2Bunsubscribe@google­groups.com>


> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/testng-users?hl=en.
>
> > --

> > ***Cédric
> > *

testng user

unread,
Dec 23, 2009, 5:15:15 PM12/23/09
to testng-users
Hello Cedric,

I already removed the variable and moved it to beforeGroup("A").
MyHelper object was not declared inside the BeforeSuite in my actual
code. Sorry for the mistake.

Thanks.

> > - Show quoted text -- Hide quoted text -

Reply all
Reply to author
Forward
0 new messages