In my grails application I use Spock and Geb to perform functional tests.
Since all test run on the same database, I would like to provide order in which CRUDSpec classes being executed. How this can be specified?
Example
First class tests blog author creation
Second class, assuming first test run successfully, tests post creation
Third class adds comments to the post
It turned out that order can be specified as follows:
grails -Dserver.port=8090 test-app functional: LoginCRUDSpec,PayeeCRUDSpec
Another example using packages from here:
// Run all tests in the “admin” package
grails test-app functional: admin.**.*
// Run all tests in the “cart” package
grails test-app functional: cart.**.*
The ultimate way to order tests with no-arg 'grails test-app' is to name test classes alphabetically.
T001_LoginCRUDSpec
T002_PayeeCRUDSpec
T003_ServiceCRUDSpec
T004_DescrParamCRUDSpec
Related
I have some Java code in my Grails project.
I have JUnit tests for them written in Java.
How can I add those tests to my Grails application?
For Grails 3 you can drop unit tests written in Java under src/test/groovy and they will be picked up and executed when tests are run (./gradlew test, for example). If you really want them under src/test/java/ that can be made to work with a little extra config in your build.gradle, but src/test/groovy/ will Just Work™.
I was wondering whether it is possible in grails to run the integration tests for a single controller. For running all integration tests, i use
grails test-app -integration
how do i run the integration test for 1 controller whose name is SurveyController.
I appreciate any help! Thanks!
Hi please specify the full path of the integration test(copy the reference of it) class as below..
grails test-app -integration path_to_integration_test.SurveyControllerIntegrationSpec
Note: Specify the test class name not controller name.
It should work
grails test-app integration: SurveyController
I have a simple application with some tests.
Actually, there is 1 JUnit test and some Specifications.
The thing is that when I run each of them separately they work fine.
But when I run:
grails test-app
It's not executing all the tests. All the tests are unit tests but they are in separate packages. But even into the package from the one it's executing, there is another test almost equal, but this one is not being executed as well...
Running grails test-app -unit I get the same problem.
Someone know if I need to do something else to be able to execute them all executing the grails test-app command?
Hm my previous answer was deleted for some reason, but be sure that the Spock test ends with Spec, rather than Test. If it ends with Test, then it will not be picked up.
e.g. MyTest -> MySpec
I am using Spock plug-in in my grails-2.3.4 application for automated unit and integration tests. When I run grails test-app, all the test cases run two times. Also in test report, every spec file is listed twice. As the application grew, number of test cases also grew, and all of them run twice. This takes double time to execute all of the test cases while development and deploying through Jenkins. Can anyone help me fix it (any help will be appreciated)?
http://grails.github.io/grails-doc/2.3.4/guide/upgradingFromPreviousVersionsOfGrails.html -> Spock included by default
You no longer need to add the Spock plugin to your projects. Simply
create Spock specifications as before and they will be run as unit
tests. In fact, don't install the Spock plugin, otherwise your
specifications will run twice [...].
In some other testing frameworks I'm used to tagging tests, eg #really_slow, #front_end
And then running different batches of tests, like I might want to set up a build slave to run all the really_slow tests, and might want to run all the tests tagged as front end but none that are marked as really slow.
To run my spock+geb tests in grails at the moment I just run grails test-app functional:
How do I tell it to run a subset?
You could use JUnit suites with #Category. Or you could use a SpockConfig.groovy with the following contents:
runner {
include foo.bar.FrontEnd, foo.bar.BackEnd
exclude foo.bar.Slow
}
Here, foo.bar.FrontEnd, foo.bar.BackEnd, and foo.bar.Slow are your own annotations. To activate the configuration file, you have to set a spock.configuration system property pointing to it.