I've faced a problem with unit testing web flow controllers
There's an existings WebFlowUnitTestMixin for unit testing webflow in GDK,
but no word on how to use it in the latest Grails 2.2.0 official documentation.
I've used spock framework for my web flow controller unit test. Here is a pretty simple example:
/* SignUpControllerSpec.groovy */@TestMixin(WebFlowUnitTestMixin)@TestFor(SignUpController)classSignUpControllerSpecextendsSpecification{def"test empty signup form submission"(){when:"user loads page with registration form"registerFlow.start.action()then:"empty userCommand object is created and lastEvent is start"lastEventName=='start'flow.userCommandinstanceofUserCommandwhen:"user submits the form with empty lines"registerFlow.signUp.on.submit.action()then:"userCommand with errors is returned"flow.userCommand.hasErrors()lastEventName=='signUp'lastTransitionName=='submit'}}/* SignUpController.groovy */classSignUpController{defuserServicedefregisterFlow={start{action{flow.userCommand=newUserCommand()}on('success').to('signUp')}signUp{on('submit'){bindData(flow.userCommand,params)defcmd=flow.userCommandif(!cmd.validate()){returnerror()}// TODO: process valid userCommand}.to('end')}end{redirect(uri:'/')}}}
All of the default unit test controller properties are available + flow, conversation, lastTransitionName,
lastEventName, currentEvent
Have fun!
If you're looking for a developer or considering starting a new project,
we are always ready to help!