In the attribute method, one indicates the action of the function in the when: block, the result of which is checked in the subsequent then: block. Often, preparation is required, which is done in the given: (or setup: or fastening method) clause. It is equally useful to include preconditions: these are conditions that are not the subject of a feature test (thus, they should not be in when: - then: or expect: , but they state / document the necessary conditions for the test to be significant. See for example the dummy parameter below:
import spock.lang.* class DummySpec extends Specification { def "The leading three-caracter substring can be extracted from a string"() { given: "A string which is at least three characters long" def testString = "Hello, World" assert testString.size() > 2 when: "Applying the appropriate [0..2] operation" def result = testString[0..2] then: "The result is three characters long" result.size() == 3 } }
What is the suggested practice for these prerequisites? I used assert in this example, but many are unhappy with assert in Spec.
source share