Spockframework 软断言只描述第一次失败

Spockframework soft assertion describes only first fail

Spockframework 提供软断言机制,但它似乎不能正常工作(至少在我的配置中)。

我创建了最简单的测试:

verifyAll {
    1 == 2
    2 == 3
}

我希望看到两条失败消息,但我只看到第一条:

Condition not satisfied:

1 == 2
  |
  false

第二个也执行了,但只出现在gradle报告中:

org.example.SoftAssertionsTest > simplest test FAILED
    org.spockframework.runtime.SpockComparisonFailure at SoftAssertionsTest.groovy:9
    org.spockframework.runtime.SpockComparisonFailure at SoftAssertionsTest.groovy:10

版本:

compile 'org.codehaus.groovy:groovy-all:2.5.8'
testCompile group: 'junit', name: 'junit', version: '4.12'

testImplementation("org.springframework.boot:spring-boot-starter-test:2.+")
testImplementation('org.spockframework:spock-spring:1.3-groovy-2.5')

我已经把这个例子推送到:https://github.com/fergus-macdubh/spock-soft-assertions

有没有办法让它显示所有消息?

好的,我在本地安装的旧 4.4.1 Gradle 版本中看到了类似的行为。但是一旦我将 gradlew[.bat] 文件添加到您的项目并将您的构建文件修改为更类似于 Spock example project,它就起作用了。

apply plugin: "groovy"

group = 'org.example'
version = '1.0-SNAPSHOT'
description = "Soft Assertions"

// Spock works with Java 1.8 and above
sourceCompatibility = 1.8

repositories {
  mavenCentral()
}

dependencies {
  // mandatory dependencies for using Spock
  compile "org.codehaus.groovy:groovy-all:2.5.8"
  testCompile platform("org.spockframework:spock-bom:2.0-M1-groovy-2.5")
  testCompile "org.spockframework:spock-core"
  testCompile "org.spockframework:spock-junit4" // you can remove this if your code does not rely on old JUnit 4 rules

  // optional dependencies for using Spock
  testCompile "org.hamcrest:hamcrest-core:1.3" // only necessary if Hamcrest matchers are used
  testRuntime "net.bytebuddy:byte-buddy:1.9.3"          // allows mocking of classes (in addition to interfaces)
  testRuntime "org.objenesis:objenesis:2.6"    // allows mocking of classes without default constructor (together with CGLIB)

  // dependencies used by examples in this project
  testImplementation("org.springframework.boot:spring-boot-starter-test:2.+")
  testImplementation('org.spockframework:spock-spring:1.3-groovy-2.5')
}

test {
  useJUnitPlatform()
}

控制台日志现在看起来符合预期:

Testing started at 12:57 ...

> Task :compileJava NO-SOURCE
(...)
> Task :test

Multiple Failures (2 failures)
    org.spockframework.runtime.SpockComparisonFailure: Condition not satisfied:

1 == 2
  |
  false

    org.spockframework.runtime.SpockComparisonFailure: Condition not satisfied:

2 == 3
  |
  false

(...)