mercredi 4 mars 2015

Grails Spock Unit Test - What is "1 *" and why "too few invocations"?

I see the following code within a Unit Test for a controller that I have inherited from others:



when: "When the controller executes a registration"
controller.index()

then: "the signup should show registration again"
1 * controller.cService.getRegions() >> []
1 * controller.dService.chkAvail(_) >> "AVAILABLE"
1 * controller.uService.createUser(_) >> { a-> throw new RuntimeException("Roll me back!")}
1 * controller.pService.registerPayMethod(_) >> { cc-> true }
view == "/signUp/su"


I understand the basics of spock unit tests, but I don't understand these 1 * lines.


I am also getting multiple errors such as:



junit.framework.AssertionFailedError: Too few invocations for:

1 * controller.cService.getRegions() >> [] (0 invocations)

Unmatched invocations (ordered by similarity):

None

Aucun commentaire:

Enregistrer un commentaire