create-unit-test

Purpose

Examples

Description

Creates a unit test for the given base name. The argument is optional, but if you don't include it the command will ask you for the name of the controller.

A unit test differs from an integration test in that the Grails environment is not loaded for each test execution and it is left up to you to perform the appropriate mocking using GroovyMock or a mock library such as GMock or EasyMock

Refer to the section on Unit Testing of the user guide for information on unit vs. integration testing.

The name of the test can include a Java package, such as org.bookstore in the final example above, but if one is not provided a default is used. So the second example will create the file test/integration/<appname>/BookTests.groovy whereas the last one will create test/integration/org/bookstore/BookTests.groovy directory. Note that the first letter of the test name is always upper-cased when determining the class name.

If you want the command to default to a different package for tests, provide a value for grails.project.groupId in the runtime configuration.

Note that this command is just for convenience and you can also create integration tests in your favourite text editor or IDE if you choose.

Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
Sponsored by SpringSource