Is there a way to get the specific statement that caused failure when using the "with" clause in Spock

StackOverflow https://stackoverflow.com/questions/21467061

  •  05-10-2022
  •  | 
  •  

Вопрос

What I am trying to find is that if there is a way to identify the specific assert that caused the error when the asserts are inside a "with".

Ideally, I would like to see the same specific result for both tests.

The result of a given test is:

Condition not satisfied:

testInstance.with { trueParam falseParam }
|            |
|            false
SpockSpec$TestMe@1cf4af1e

    at SpockSpec.Does not provides specific failure(SpockSpec.groovy:10)


Condition not satisfied:

testInstance.falseParam     // expected to fail
|            |
|            false
SpockSpec$TestMe@24c2ffbc

    at SpockSpec.Provides specific failure(SpockSpec.groovy:19)

Code:


import spock.lang.Specification
import spock.lang.Unroll

@Unroll
class SpockSpec extends Specification {
    def testInstance = new TestMe(trueParam: true, falseParam: false)

    def "Does not provides specific failure"() {
        expect:
        testInstance.with {
            trueParam
            falseParam
        }
    }

    def "Provides specific failure"() {
        expect:
        testInstance.trueParam
        testInstance.falseParam     // expected to fail
    }

    class TestMe {
        boolean trueParam, falseParam
    }
}

Это было полезно?

Решение

Try

def "Does not provides specific failure"() {
    expect:
    with( testInstance ) {
        trueParam
        falseParam
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top