If I generate a contoller using the command “create-controller” Grails generates the contoller and a unit test (using the template /src/templates/scaffolding/Test.groovy).
After changing bits of the template I now want to generate the unit tests anew but Grails won’t generate them. I tried:
"create-unit-test"but this will use the template /src/templates/testing/UnitTest.groovy
and
"create-integration-test"will use the template /src/templates/testing/Generic.groovy
So how can I generate unit test for controller using the Test.groovy template?
When creating artifacts or using scaffolding, Grails uses templates to create the domain classes, controllers, views, etc. The default templates are part of the Grails distribution for out of the box behaviour, but can be customized for project specific needs.
Copies the the templates used by Grails during code generation to your project directory:
The artifacts directory contains the templates used by the create-* commands.
The scaffolding directory contains templates used by the generate-* commands.
The war directory contains the web.xml template used to generate the deployment descriptor.
So you need to edit:
src/templates/artifacts/Tests.groovyfile, when executegrails create-unit-testorgrails create-integration-testcommands.src/templates/scaffolding/Test.groovywhen executegrails generate-allorgrailscommands.generate-controller
In your case regenerate your controller test and overwrite only your test file: