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

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

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 with Java JUnit tests

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

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

How do I run a subset of spock functional tests in grails?

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.

Resources