What's good style for preconditions in Spock feature methods? -
in feature method, 1 specifies feature action in when: block, result of gets tested in subsequent then: block. preparation needed, done in given: clause (or setup: or fixture method). equally useful include preconditions: these conditions not subject of feature test (thus should not in when:-then: or expect:) assert/document necessary conditions test meaningful. see example dummy spec below:
import spock.lang.*  class dummyspec extends specification {   def "the leading three-caracter substring can extracted string"() {     given: "a string @ least 3 characters long"     def teststring = "hello, world"      assert teststring.size() > 2      when: "applying appropriate [0..2] operation"     def result = teststring[0..2]      then: "the result 3 characters long"     result.size() == 3   } } what suggested practice these preconditions? used assert in example many frown upon asserts in spec. 
i've been using expect such scenarios:
@grab('org.spockframework:spock-core:0.7-groovy-2.0') @grab('cglib:cglib-nodep:3.1')  import spock.lang.*  class dummyspec extends specification {   def "the leading three-caracter substring can extracted string"() {     given: "a string @ least 3 characters long"     def teststring = "hello, world"      expect: "input should have @ least 3 characters"     teststring.size() > 3      when: "applying appropriate [0..2] operation"     def result = teststring[0..2]      then: "the result 3 characters long"     result.size() == 3   } } 
Comments
Post a Comment