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.
Related
I have a Spock unit test in a Grails app. In IntelliJ IDEa I can either run it with grails environment and then it means I wait a minute until the environment loads to run the test even though I do not need the environment.
The other option is to run it with JUnit. This works nicely in a Grails app without my own plugins. However, when I run it in a Grails app that has a plugin of another Grails app I have, it crashes on NoClassFound. It does not see the classes from the plugin that I included.
When I checked in IDEa the project structure, indeed the sources nowhere include a folder where the plugin classes would be included. For some reason the plugins in plugins section in BuildConfig.groovy do not appear in the classpath anywhere, they are not found in the external libraries section or anywhere else.
Is there a way to tell grails not to spin up its environment when running some of my tests? Or how can I include my plugin in the classpath for Groovyc to see it when building for testing?
The problem occurs also when simply pressing Build Project in IntelliJ IDEa. The project we are working with is simply run with grails and is never built (beyond how grails builds it). When you try to build it in IDEa, it fails on NoClassDefFound of plugin class.
Versions:
IntelliJ IDEa 2021.2
Grails 2.5.6
EDIT: Ok, it seems like grails apps are to be tested via their command-linke with grails test-app. When Grails runs in interactive mode, test-app won't have to reinitialize the environment, cause it's already running, so it runs faster.
However, as I found here Slow Grails test starting in Intellij IDEA it seems like there's no way to run grails in interactive mode from within IDEa in a way that would enable IDEa test runs to use such interactive console. Which means I'm forced to run tests via command-line. Not happy.
Edit 2: At some point in time I have managed to get the compiled tested.class to the out folder. This enabled running the test instantly via IDEa circumventing the Grails glory. However, I have no idea how I got it to out folder and after removing it I am unable to compile it again and get it there.
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 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.
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 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