How to run integration test on one controller? - grails

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

Related

Running a single integration test/ single test class

I was trying to run a single test or a single class from the grails cli, but no matter what I tried I am unable to find out how to do that. Does anyone of you have an idea what could be the command for doing that?
What I tried so far
test-app -integration -Dtest.single=package.ClassSpec: still runs all of the tests. Replacing package with a wildcard doesnt change anything.
test-app *ClassSpec* -integration: runs 10 actionable tasks, not entirely sure which tests are these, the class doesnt have 10 tests.
I am using Grails 3.3.2
./grailsw test-app MyClass
(without Spec or Test at the end)
http://docs.grails.org/3.1.1/ref/Command%20Line/test-app.html

Grails 3.1.5 integration vs functional testing

I added geb/spock to my build.gradle and my project compiles as expected. However, I am confused with the difference between running Integration tests and running Functional tests.
I created 2 tests with "grails create-integration-test foo" and "grails create-functional-test bar"
When I execute "grails test-app --functional", both tests for foo and bar run.
How do I isolated the running of bar? Also is a geb.config needed in Grails 3.1.5 application. I can not find any documentation that addresses that issue.
thanks
I am confused with the difference between running Integration tests and running Functional tests.
Functional tests are a type of integration test. Test execution in Grails 3 is handled by Gradle, so I believe you can archive desired behavior playing with one.
How do I isolated the running of bar?
Simple workaround would be placing tests in different packages, so you can use patterns when running them, e.g.
grails create-integration-test org.functional.foo
grails create-functional-test org.integrational.bar
grails test-app org.functional.*
grails test-app org.integrational.*
You can read more about patterns here
Also is a geb.config needed in Grails 3.1.5 application
As mentioned here GebConfig.groovy is not nessesary until you need additional configuration.

How to run specific list of specs using Jenkins, Grails and Geb/Spock

I have 2 questions:
What is the right command to execute a specific list of tests in Jenkins?
We have a Jenkins instance up and running and have set up a grails job to run our functional tests. Jenkins runs fine when specifying no spec or specifying 1 spec. However, when passing it 2 specs, only the first spec runs.
In the command line, I run my tests as such: grails test-app functional: TestASpec TestBSpec2 and it works.
In Jenkins, I tried:
"test-app -functional -Dgeb.build.baseUrl=http://localhost:32000/MyApp TestASpec Test2Spec" but it doesn't work.
TestASpec would run but not Test2Spec.
"test-app -functional -Dgeb.build.baseUrl=http://localhost:32000/MyApp TestASpec" would run fine.
I don't understand the meaning of baseUrl and also, do arguments passed to the command line overwrites the ones defined in GebConfig?
Thanks in advance
Olivier
My bad, I just had to replace -Dgeb.build.baseUrl by -Dgeb.baseUrl and it all worked as expected.
-Dgeb.build.baseUrl=http://localhost:32000/MyApp
is JVM argument that set geb framework url to test against.
Same way you can set the enviroment property to tell geb what driver to use
-Dgeb.env=firefox
if Jenkins runs only grails command it should be set as
so I guess your command should be
test-app -functional: TestASpec TestBSpec2 --baseUrl=http://localhost:32000/MyApp

Grails Geb tests execution order

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

How can I specify environment for Spock test?

How can I specify test environment for specific Spock test other than default one?
As you can use the spock framework via command like (http://grails.org/plugin/spock, see Running Tests section), like this:
grails test-app :spock
you should be able to specify the environment as well, pretty much like this:
grails [environment]* test-app :spock
because the test-app script allows environment option.
Let me know if this works for you. :)
EDIT:
As you noticed me, the solution above applies for every test in your application. In order to annotate every single test for a specific environment, I think you should have a look at this plugin:
http://www.grails.org/plugin/spock-grails-env-extensions
Thank you. This exactly what I was looking for. Unfortunately current
version of plugin doesn't work with Spock v0.6 =( – fedor.belov Aug 22
'12 at 10:52
It works, you just have to comment dependsOn out (using Spock v0.7).
https://github.com/osoco/grails-spock-env-extensions/blob/master/SpockGrailsEnvExtensionsGrailsPlugin.groovy

Resources