Reputation: 1597
First of all, I am shocked at the lack of documentation for implementing front-end tests for Grails. The GroovyPagesTestCase class makes testing super easy, so easy there is no excuse for FE Devs not to test. But anyway, here is my question. At my job, I am running Grails with Maven. When I need to run my tests, the only successful command to execute the tests is:
mvn grails:test-app
and that runs all tests. But, I really want to move faster when test-driving code, does anyone know how to only run integration tests in this kind of environment? Not finding anything on my own.
Upvotes: 0
Views: 1592
Reputation: 162
On grails 2.x this is what works best for me:
All integration tests:
mvn grails:exec -Dgrails.env=test -Dcommand=test-app -Dargs=:integration
Single test class:
mvn grails:exec -Dgrails.env=test -Dcommand=test-app -Dargs=:integration -Dargs=NameOfYourIntegrationTests
Single method in a test class:
mvn grails:exec -Dgrails.env=test -Dcommand=test-app -Dargs=:integration -Dargs=NameOfYourIntegrationTests.testMethod
Hope it helps
Upvotes: 0
Reputation: 172788
mvn -Dargs=CircleTests -Dcommand=test-app grails:exec
mvn grails:test-app will always execute all tests
Best combine that with -unit
/ -integration
to avoid the time-consuming preparation for the other phase (example uses a test named CircleTests
; drop the suffix in the arguments):
mvn -Dargs="-unit Circle" -Dcommand=test-app grails:exec
You may use patterns and multiple names, separated by spaces:
mvn "-Dargs=Square Ci*le" -Dcommand=test-app grails:exec
Grails also understands the special -unit and -integration names:
mvn -Dargs=-unit -Dcommand=test-app grails:exec
Or to run a single method:
mvn -Dargs=Circle.DrawSmallEllipse -Dcommand=test-app grails:exec
With the new Grails version this does not work any more because grails:exec runs in dev mode instead of test mode. You can now execute either of:
mvn -Dgrails.cli.args="integration: Circle" grails:test-app
mvn -Dgrails.cli.args="-integration Circle" grails:test-app
mvn -Dgrails.env=test -Dargs="integration: Circle" -Dcommand=test-app grails:exec
Upvotes: 2
Reputation: 2453
The grails command for this is grails test-app :integration
.
Given that, I believe you should be able to use the grails:exec goal to run an arbitrary command, like this- mvn grails:exec -Dcommand=test-app -Dargs=:integration
.
Not quite sure how mvn will handle the colon after the equals sign. You might try quotes or double-quotes around :integration
if the vanilla syntax won't cut it.
This based on http://grails.org/doc/latest/guide/commandLine.html#4.5 Ant and Maven.
Update: grails test-app -unit
and grails test-app -integration
are also supported, which may be more to Maven's liking.
Upvotes: 3