How can I add more data to assertion message?
Asked Answered
G

3

8

Spock has great assertion support. But I've got one problem - I wanna add more context data (for example url of the checked page) to assertion info.
I've tried assert a == b, [context] but in this case Spock doesn't print a and b values

Gallion answered 12/11, 2013 at 8:46 Comment(0)
R
12

You can either rely on the default condition output, or define a custom message as already explained in another answer (e.g. assert a == b : "my message involving $url"). Besides you can customize the method name:

@Unroll
def "log in to #theUrl"() {
    ...
    where:
    theUrl = ...
}

You would typically use this if you wanted to repeat the same test for different URLs, but you can also use it for a single URL.

Rozella answered 12/11, 2013 at 14:57 Comment(0)
C
2

Why just not do add a and b into the list after colon?

assert a == b, [a, b, context]

I know this is kind of redundant and message won't be formatted in nice Spock way, but still you can format it with GString in the way suitable for your need.

Computation answered 12/11, 2013 at 11:40 Comment(0)
P
1

I don't believe you can. Not sure what your test looks like, but maybe the @Unroll annotation could help here?

Pressey answered 12/11, 2013 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.