File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
Register / Login


JavaRanch » Java Forums » Other Languages » Groovy
Reply 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
Bartender

Joined: Oct 04, 2006
Posts: 2160
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!
 
 
subject: Unit Testing and Accessing Private Methods and Instance Variables
 
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture