Spock Tag Combinations

There | have | so many | Spock | spec examples of using your labels, for example:

// when -> then label combo
def "test something"() {
    when:
    // blah

    then:
    // blah blah
}

Label combinations such as:

  • whenthen
  • givenwhenthen
  • expect
  • givenexpect

But nowhere can I find documentation about what legal / meaningful combinations of these labels are. For example, can I:

def "do something"() {
    when:
    // blah

    expect:
    // blah
}

Can I? I dont know. What about:

def "do something else"() {
    when:
    // blah

    then:
    // blah

    expect:
    // blah

    where:
    // blah
}

Can I? Again, I do not know. But I wonder.

+4
source share
1 answer

. , - , . , , , . , http://spockframework.imtqy.com/spock/docs/1.0/spock_primer.html. . :

Spock Tags

, , . , , , . , , . :

[...] , .

. .

def "test"() {
    when:
        println("test")

    expect:
        1==1
}

, .

: /Users/wooki/IdeaProjects/mylibrary/src/test/ groovy/ExampleTest.groovy: 13: "" ; : [, ] @ 13, 9.

. , , .

def "do something else"() {
    when:
    // stimulus

    then:
    // 1st verification

    and:
    // 2nd verification

    where:
    // parametrization
}

, , - , . , , - , , , Spock.

def "do something else"() {
    when:
    // stimulus

    then: "1 is always 1"
       1 == 1

    and: "2 is always 2"
       2 == 2
}

, , ( , ), .

, . . , , , . , .

- :

def "test"() {
    given:
        def value

    when:
        value = 1

    then:
        value == 1

    when:
        value = 2

    then:
        value == 2
}

, , " ". , , , , , -, , .

, .

+9

Source: https://habr.com/ru/post/1611041/


All Articles