0

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.

Mario David
  • 1,595
  • 11
  • 19

1 Answers1

1

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>"
    ]
}
Martin Hauner
  • 1,593
  • 1
  • 9
  • 15
  • works great! to do programming in config files is a pretty cool feature of groovy. When executing geb in this scenario, i currently get some import errors on the page objects in the step definitions. Any thoughts on that one? thx – Mario David Jun 16 '14 at 11:08
  • You are talking about page objects in the plugins folder? I did not try that but i guess that is because the plugins test/functional folder is not in the class path... – Martin Hauner Jun 18 '14 at 06:04
  • yes, page objects in the plugin folder, exactly. So, you say test/functional of the plugins is not in the classpath, right? If you could give me some kind of advice how to achieve this, i would be very glad, because i really have no idea to get that done. Is this something, where grails-cucumber or even grails has to be modified, or is this just a config thing? – Mario David Jun 18 '14 at 19:06
  • thinking about it, we have to tell grails that test/functional in the plugin is a source folder. There is a `source` option in grails-cucumber that may work. It will compile the stuff from the given folders. The `glue` path must be changed to load the compiled code via `classpath` notation. This is for compiling steps. Not sure if this works for the geb code. – Martin Hauner Jun 20 '14 at 06:57