Issue Details (XML | Word | Printable)

Key: GRAILS-2629
Type: Bug Bug
Status: Resolved Resolved
Resolution: Duplicate
Priority: Major Major
Assignee: Graeme Rocher
Reporter: Mike Hugo
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Grails

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

Created: 12/Mar/08 06:54 AM   Updated: 01/Apr/08 09:01 AM   Resolved: 01/Apr/08 09:01 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide

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?



Mike Hugo added a comment - 01/Apr/08 09:01 AM

Duplicate of GRAILS-2630