Spock: Can not use @BeforeClass together with def setupSpec()

Created on 7 Jul 2016  路  3Comments  路  Source: spockframework/spock

Issue description

See subject

How to reproduce

class SomeSpec extends Specification {

    @BeforeClass
    def setupSpec() {
        dbConnection.initialize()
    }
}

Exception

java.lang.IllegalAccessException: Class org.spockframework.util.ReflectionUtil can not access a member of class info.solidsoft.training.spockbasics.cleanup.CleaningUp1Spec with modifiers "private"

Proposition

Maybe more meaningful description? There is no point of using those two technics together.

Java/JDK

1.8.0_60

Groovy version

2.4.7

Build tool version

Gradle

2.2

Operating System

Windows 7

IDE

IntelliJ

Build-tool dependencies used

Gradle/Grails

compile 'com.google.guava:guava:17.0'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'org.springframework:spring-web:4.0.5.RELEASE'

testCompile 'junit:junit'
testCompile 'org.mockito:mockito-core'
testCompile 'org.assertj:assertj-core'
testCompile 'pl.pragmatists:JUnitParams'
testCompile "pl.wkr:fluent-exception-rule"
testCompile 'info.solidsoft.mockito:mockito-java8'

testCompile 'org.spockframework:spock-core:**1.1-groovy-2.4rc-1**'
testCompile 'cglib:cglib'
not a bug

Most helpful comment

Just remove the annotations.

All 3 comments

Thanks for the report :).

This is also reproducible with setup() and @Before. That issue seems to be introduced in Spock 1.0 in which support for JUnit annotations was added.

Just remove the annotations.

The problem here is not very intuitive error message:

java.lang.IllegalAccessException: Class org.spockframework.util.ReflectionUtil
can not access a member of class info.solidsoft.training.spockbasics.cleanup.CleaningUp1Spec 
with modifiers "private"

which could be enhanced.

Was this page helpful?
0 / 5 - 0 ratings