JanKanis
JanKanis

Reputation: 6682

How do I run a single integration test in grails 3?

Grails 3 (at least 3.1.10) is flaky in running only specific tests. How do I get it to run a single integration test?

Upvotes: 10

Views: 3495

Answers (3)

Jonathan Tse
Jonathan Tse

Reputation: 995

Here is a sample command to run a single integration test

grails test-app *LoginFunctional* -integration

If you put -integration flag before pattern, the test-app command will ignore the pattern and execute all integration tests.

Upvotes: 13

JanKanis
JanKanis

Reputation: 6682

The official command line syntax is grails test-app, optionally followed by a pattern to match the full namespaced class name of what you want to test such as org.myorg.ClassToTest or org.**.*, and -unit or -integration to select a specific phase. See the docs.

There are a number of quirks in Grails 3.1.10, though.

1) grails test-app won't always run the tests, probably a bug in the dependency management. If you first remove the test report at build/reports/tests/index.html grails will see that it actually needs to do something to generate a new report.

2) Sometimes things just go randomly weird. If so, do grails clean; grails test clean. (I didn't yet figure out if you really need both of them or only one of the two.)

3) The official way should work, but do (2) first if it doesn't. Also, if you want to run only a specific integration test you need to add -integration or you'll get an error. I think without such a flag Grails unconditionally first tries to run unit tests and then integration tests, and if your test pattern does not match any unit tests grails will error out. Similarly if the pattern only matches unit tests add -unit or you'll get an error, though you still get the correct test report in this case.

4) There's also an alternative way, by using the -Dtest.single=<classname> flag. This sets a system property that is picked up by gradle. I only got it working properly if I also added a -unit flag, but I didn't investigate very deep.

Upvotes: 2

Michal_Szulc
Michal_Szulc

Reputation: 4177

I usually use annotation @IgnoreRest. Remember to import spock.lang.IgnoreRest and run test on specified class.

Upvotes: 1

Related Questions