Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Test methods and Before methods are found differently using reflection
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
  1 message - 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
 
Johan Haleby  
View profile  
 More options Sep 11 2009, 3:11 pm
From: Johan Haleby <johan.hal...@gmail.com>
Date: Fri, 11 Sep 2009 12:11:16 -0700 (PDT)
Local: Fri, Sep 11 2009 3:11 pm
Subject: Test methods and Before methods are found differently using reflection
Hi,

I'm developing TestNG (5.10) support for PowerMock and I've run into
some issues. What I what to do is to add support for automatically
creating mocks and injecting them before each test method is executed
without forcing the user to declare anything in the TestNG xml file
(expect for the PowerMockObjectFactory class).

My first attempt was to programmatically add a listener from my
ObjectFactory but I couldn't find a way to do that (please point me in
the right direction if this is possible). So as a work-around I
created a proxy using Javassist of the test class and before each test
or "before" method invocation I'm creating and injecting the mocks.
This works fine when with standard test methods but when TestNG
executes the before method I get an exception IllegalArgumentException
saying that "object is not an instance of declaring class".

The reason is that the "thisMethod" argument in
MethodHelper#invokeMethod(..) points to the original test class method
in case of before methods (in my case it points to public void
samples.testng.AnnotationDemoWithBeforeMethodTest.setup()" but it
points to the proxied method in case of test method invocations (in my
case public final void samples.testng.AnnotationDemoTest_$
$_javassist_0.assertInjectionWorked() throws java.lang.Exception). So
there seems to be a difference in the way that TestNG looks up the
method to execute using reflection when it comes to test methods and
before methods. Why is this? And more importantly, how can I solve my
issues?

The code is available in the PowerMock svn repo at
http://powermock.googlecode.com/svn/trunk/modules/module-impl/testng
and the test case (which is current not included in the suite.xml
because it fails the build) is available at
http://code.google.com/p/powermock/source/browse/trunk/modules/module....

/Johan


    Forward  
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 »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google