Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unit Testing and Accessing Private Methods and Instance Variables  RSS feed

Ivan Krizsan
Ranch Hand
Posts: 2198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!