Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 988
JanKanis Avatar asked Sep 29 '16 13:09

JanKanis


People also ask

Where can I run an integration test?

The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.

How do you run a pipeline integration test?

In order to run Integration Tests in your release pipeline. You should include your Test projects or test assembly dll files in the artifacts published in your build pipeline. So that your Integration test projects are accessible to the test tasks in your release pipeline. To Include your test files in the artifacts.

Can jest run integration tests?

In general, Jest can run seven integration tests in parallel. The biggest impact on the duration for integration tests is the starting of the different docker containers.

Can you use JUnit for integration tests?

3.1.JUnit 5 defines an extension interface through which classes can integrate with the JUnit test. We can enable this extension by adding the @ExtendWith annotation to our test classes and specifying the extension class to load.


2 Answers

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.

like image 68
Jonathan Tse Avatar answered Nov 16 '22 00:11

Jonathan Tse


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.

like image 32
JanKanis Avatar answered Nov 16 '22 00:11

JanKanis