This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Groovy and the fly likes Unit Testing and Accessing Private Methods and Instance Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Unit Testing and Accessing Private Methods and Instance Variables" Watch "Unit Testing and Accessing Private Methods and Instance Variables" New topic
Author

Unit Testing and Accessing Private Methods and Instance Variables

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Currently, Groovy allows for access of private instance-methods and variables from outside the class. This is convenient in certain unit test scenarios, since it allows me to write simpler tests without having to use a testing framework (like PowerMock). However, as far as I understand this is basically a bug in Groovy (see http://jira.codehaus.org/browse/GROOVY-1875).
I fear that if I use this "feature", my unit tests will break the day Groovy 2.0 (or the version in which this is fixed) is released.
My question is: Does anyone have any experiences to share on how to solve this issue in Groovy?

I already know about PowerMock and I also know how to use Java reflection - I am wondering if there is a more "Groovy", a more elegant, way of doing this without relying on the above mentioned bug?
Many thanks in advance!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unit Testing and Accessing Private Methods and Instance Variables
 
Similar Threads
mocking private static methods with PowerMock
Unit Testing with Groovy?
testing private methods with junit?
integrating SpringContextTests with PowerMock
TestNG vs JUnit, mockito + Powermock vs jmockit