Search code examples
testinggroovy

Testing private methods in groovy


In Java it is very extended to enforce the use of package-protected instead of private in order to make easier to test methods.

Now i am switching to Groovy and one of the first things i noticed is the public by default access modifier and, later, that package-protected is not very clean and easy to use in Groovy as it was in Java.

Then i also realized about private fields and private methods are not private "bug" --> https://issues.apache.org/jira/browse/GROOVY-1875

... but, of course, this is a bug that may be solved at some moment so i shall not rely on this (Shall i?)

So ... what is the prefered way to test restricted methods in groovy?


Solution

  • Basically the question is if Groovy will in the future ignore private visibility too. You can be sure that in Groovy 2.x this won't be fixed. It might get in a future new major version like Groovy 3. But this version will then contain incompatible fixes anyway, plus it is most likely, that there will be still a way to get the old functionality. So for the near future don't expect that to be "fixed"