diff --git a/grails-testing-support/src/test/groovy/grails/testing/spock/JUnitAnnotationSpec.groovy b/grails-testing-support/src/test/groovy/grails/testing/spock/JUnitAnnotationSpec.groovy new file mode 100644 index 00000000..3ce09aaa --- /dev/null +++ b/grails-testing-support/src/test/groovy/grails/testing/spock/JUnitAnnotationSpec.groovy @@ -0,0 +1,57 @@ +package grails.testing.spock + +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import spock.lang.Shared +import spock.lang.Specification +import spock.lang.Stepwise + +@Stepwise +class JUnitAnnotationSpec extends Specification { + @Shared + static List methodOrder = [] + + void setupSpec() { + methodOrder << "setupSpec" + } + + void setup() { + methodOrder << "setup" + } + + void cleanup() { + methodOrder << "cleanup" + } + + void cleanupSpec() { + methodOrder << "cleanupSpec" + } + + @BeforeEach + void beforeEach() { + methodOrder << "beforeEach" + } + + @AfterEach + void afterEach() { + methodOrder << "afterEach" + } + + @BeforeAll + static void beforeAll() { + methodOrder << "beforeAll" + } + + @AfterAll + static void afterAll() { + methodOrder << "afterAll" + assert methodOrder == ["beforeAll", "setupSpec", "beforeEach", "setup", "cleanup", "afterEach", "cleanupSpec", "afterAll"] + } + + void 'junit 5 annotated methods are called in correct order prior to this test'() { + expect: + methodOrder == ["beforeAll", "setupSpec", "beforeEach", "setup"] + } +} diff --git a/grails-testing-support/src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy b/grails-testing-support/src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy index b0cb78f2..04acb656 100644 --- a/grails-testing-support/src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy +++ b/grails-testing-support/src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy @@ -1,6 +1,5 @@ package grails.testing.spock -import org.junit.Before import spock.lang.Shared import spock.lang.Specification import spock.lang.Stepwise