in my grails apps, i have different plugins, that are used from all apps. these plugins have cucumber specifications and geb pages within "test/functional". What i would like to do, is in every app, that uses a plugin, the tests of the plugin should be executed withn the context of the app.
To achieve this, i would like to know, how to the configuration in the CucumberConfig.groovy of the app has to look like.
I came up with something like this:
cucumber {
tags = ["~@ignore"]
features = ["plugins/plugin-name/test/functional"]
glue = features
}
but it doesn't work out the way it should. Perhaps this is even the wrong way to achieve my goal. If it is, don't hesitate to tell me about.
If anyone has an idea, that would be great.
this worked for me:
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
String pluginDir = GrailsPluginUtils.pluginInfos.find { it.name == '<nameOfPlugin>' }.pluginDir
String pluginCukeDir = [pluginDir, 'test', 'cucumber'].join (File.separator)
println "($pluginDir) ($pluginCukeDir)"
cucumber {
tags = ["~@ignore"]
features = [
"test/cucumber", pluginCukeDir
]
glue = features
}
I used the geb example of grails-cucumber, duplicated one feature from the example into a plugins test dir and renamed the steps to avoid a DuplicateStepDefinitionException
.
Using test/cucumber
instead of test/functional
should make no difference.
Update:
taking a closer look, this will work but there are a couple of complications. You have to decide for yourself if it pays off.
If we have geb code (page objects/modules) in the plugins test code it must be compiled. We can tell cucumber-grails to do this with the sources
configuration. This will compile the given source folders (including any step code) into target/test-classes/functional
(we are in the functional test phase).
Next we have to extend the classpath of cucumber using the glue
configuration by adding
"classpath:" entries.
Issues:
Because the plugin test code is compiled into the same folder as the project test code we have to take care that the plugin code doesn't use the same packages or class names overwriting classes from the project.
We will also have to take care of the cucumber hooks. We do not want to run the @Before/@After hooks that setup geb multiple times (i.e. from the current project and its plugins). A solution should be to tag the hooks differently in the project and the plugins and add the proper tag to the tags configuration so that the geb setup hooks run only for the given tag.
The configuration will then look like this:
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
String pluginDir = GrailsPluginUtils.pluginInfos.find { it.name == '<nameOfPlugin>' }.pluginDir
String pluginCukeDir = [pluginDir, 'test', 'functional'].join (File.separator)
cucumber {
sources = [
//"test/functional", // automatically compiled by grails
pluginCukeDir // cucumber plugin tells grails to compile this
]
features = [
"test/functional",
pluginCukeDir
]
glue = [
"classpath:<inside target/test-classes/test/functional>"
]
}