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