aspose file tools*
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 Spring in Action this week in the Spring 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