Testing Labs

  • Tags : testing, utility, integration
  • Latest : 0.4.0
  • Last Updated: 12 March 2010
  • Grails version : 1.2 > *
  • Authors : null
0 vote
Dependency :
compile ":testing-labs:0.4.0"

Documentation

Summary

Installation

grails install-plugin testing-labs

Description

Testing Labs

This plugin provides extensions to the Grails testing environment in order to fix bugs and make life easier.

Functionality Provided

  • Fix for GRAILS-4460
  • "create-controller-integration-test", which accepts the logical name for the controller and constructs a controller integration test in the proper package with the appropriate set of imports and the following properties.
    • "instance" - An instance of the controller under test, also accessible via the controller's logical name (e.g.: "foo.bar.BazController" is accessible as the "baz" property).
    • "request" - The mock request attached to "instance"
    • "response" - The mock response attached to "instance"
    • "session" - The mock session attached to "instance"
    • "params" - The parameter map attached to "instance"
    • "view" - The view attached to the instance's "modelAndView"
    • "viewName" - The name of the view attached to the instance's "modelAndView"
    • "model" - The model attached to the instance's "modelAndView".
    • Spring beans - The controller instance is also autowired with any Spring beans (as of 0.3.1).

Controller Integration Test Example

The Grails integration test example would look like this using "create-controller-integration-test":

class FooController {
  def text = { render "bar" }
  def someRedirect = { redirect(action:"bar") }
}

grails create-controller-integraiton-test foo

class FooControllerTests extends ControllerIntegrationTestCase {

void testText() { foo.text() assertEquals("bar", response.contentAsString) }

void testSomeRedirect() { foo.someRedirect() assertEquals("/foo/bar", response.redirectedUrl) }