access to package private members from superclass in spec

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

access to package private members from superclass in spec

Emiliano Capoccia
Hello group,

I'm having an issue accessing a package private (default) member in a Spock test. I believe I'm doing something wrong, be patient I'm a newbie with Spock.

Here's the issue, I have a package private member declared in a superclass, for instance:

public class BaseClass {
    int packagePrivate = 3;

public class SubClass extends BaseClass { }

Now, if I write a spec like this:

class SubClassSpec extends Specification {
def "should access package private member declared in superclass"() {
def obj = new SubClass()
obj.packagePrivate == 3

Then I get: groovy.lang.MissingPropertyException: No such property: packagePrivate for class: my.pack.SubClass

However if I modify the visibility on the BaseClass to be protected (or public), then it all works fine. 

I've clearly put everything in the same package (my.pack, not the default), haven't pasted the full code for clarity. 

What am I doing wrong?

You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at
For more options, visit