Grails

Add "ControllerTestCase" that will make it easier to mock controllers for unit tests

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Per a comment on Glen Smith's blog (http://blogs.bytecode.com.au/glen/2008/03/12/mockfor-march---unit-testing-grails-controllers.html):

I think we should have a new ControllerTestCase that has a method like

def withMockController(Class c, Closure c)

that does all of the setting up of params/flash/etc.

Then you could just do

withMockController(LoginController) {
def controller = new LoginController()
lc.login(goodUser)

assertEquals "glen", session.account.userId
assertEquals "/demo/", redirectParams.uri
assertNull flash.loginError

LoginCommand badUser = new LoginCommand(userId: 'glen', password: 'unlucky')
lc.login(badUser)

assertNull session.account
assertNotNull flash.loginError
}

Thoughts? JIRA issue?

Activity

Hide
Mike Hugo added a comment -

Duplicate of GRAILS-2630

Show
Mike Hugo added a comment - Duplicate of GRAILS-2630
Hide
Graeme Rocher added a comment -

Bulk closing bunch of resolved issues

Show
Graeme Rocher added a comment - Bulk closing bunch of resolved issues

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: