Java 11.0.6, Dependencies:
testImplementation('org.spockframework:spock-core:2.0-M2-groovy-3.0')
testImplementation('org.springframework.boot:spring-boot-test: 2.2.7.RELEASE')
class OutputCaptureTest extends Specification {
@Rule
OutputCaptureRule capture = new OutputCaptureRule()
def "test output"() {
when:
println "hello"
then:
capture.toString().contains("hello")
}
}
Exception:
Condition failed with Exception:
capture.toString().contains("hello")
| java.lang.IllegalStateException: No system captures found. Please check your output capture registration.
| at org.springframework.util.Assert.state(Assert.java:73)
| at org.springframework.boot.test.system.OutputCapture.get(OutputCapture.java:129)
| at org.springframework.boot.test.system.OutputCapture.getAll(OutputCapture.java:100)
| at org.springframework.boot.test.system.OutputCapture.toString(OutputCapture.java:90)
| at org.springframework.boot.test.system.OutputCaptureRule.toString(OutputCaptureRule.java:110)
| at com.me.OutputCaptureTest.test output(OutputCaptureTest.groovy:17)
org.springframework.boot.test.system.OutputCaptureRule@5705a8db (renderer threw IllegalStateException)
Comment From: philwebb
It looks like Spock isn't executing that JUnit rule. You can try debugging your tests with a breakpoint on OutputCaptureRule.apply to confirm. I'm afraid you'll need to get help from the Spock community if that's the case.
Comment From: jmuollo
See https://stackoverflow.com/a/70350184/3059685 for a potential solution to this problem.
Comment From: kiriphorito
Another potential solution for this is to add/import: org.spockframework:spock-junit4 https://mvnrepository.com/artifact/org.spockframework/spock-junit4
I originally only had: org.spockframework:spock-spring
Comment From: ykcai
Another potential solution for this is to add/import: org.spockframework:spock-junit4 https://mvnrepository.com/artifact/org.spockframework/spock-junit4
I originally only had: org.spockframework:spock-spring
This fixed my issues!