Grails with Java JUnit tests - grails

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™.

Related

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.

Grails test-app is not executing all the tests

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

Grails test cases run twice when I execute grails test-app

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 [...].

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

Unit testing a grails plugin which uses another plugin

I am writing a Grails plugin for my project which uses a another grails plugin, written by another group in the organization. I want to unit test my grails plugin code, but it uses the this other plugin, and when I unit test, my code fails because the other plugin is not loaded.
How do I load this other plugin before my unit tests are run?
I realised that I could get the same done with integration tests. So wrote integration test instead of unit tests.

Resources