Skip to content

Commit

Permalink
Fix #157 - Add test cases to verify ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
longwa authored and jdaugherty committed Sep 25, 2024
1 parent 7354997 commit fb9035d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<String> 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"]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package grails.testing.spock

import org.junit.Before
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Stepwise
Expand Down

0 comments on commit fb9035d

Please sign in to comment.