How to split setup between multiple tests using spock w / groovy structure

I am new to installing and noticed the installation: the step in the specification is localized for this particular test. How can I share the settings for these devices, similar to the traditional junit approach?

Thank you!

def "setup with spock"() {
    setup:
    def message = new FooMessage()
    def sut = new FooProcessor()
    def builder = Mock(FooBuilder)
    sut.setBuilder(builder)

    when:
    builder.buildFooUsing(_) >> {"bar"}
    def result = sut.process(message)

    then:
    assert result == "bar"
  }
+5
source share
2 answers

You should use setupSpec () or see the @Shared annotation if you want to share one object in tests

+4
source

From the Spock documentation

1.3.4 Exchange of objects between iterations

To split an object between iterations, it must be stored in the @Shared or static field.

. @Shared : block.

, . . , , , spec, . .

+1

All Articles