[C-JVM]Using datatables in groovy step definitions

976 views
Skip to first unread message

rsilva4

unread,
Apr 11, 2012, 5:10:57 AM4/11/12
to Cukes
I can't find anything about this in the Groovy examples. Here what I
have tried:

Given(~'^the following external datasources:$') { eds ->

def listEds = eds.asList(ExternalDataSource)
listEds.each {
print it
ExternalDataSource.create(it);
}
assert ExternalDataSource.all().size() == listEds.size()
}

That outputs:

| Running 1 cucumber test...
org.codehaus.groovy.runtime.InvokerInvocationException:
groovy.lang.MissingMethodException: No signature of method:
net.inductiva.collector.ExternalDataSource.create() is applicable for
argument types: (net.inductiva.collector.ExternalDataSource) values:
[net.inductiva.collector.ExternalDataSource : null]
Possible solutions: create(), merge(), read(java.io.Serializable),
count(), delete(), ident()

'print it' prints nothing, and trying to debug (using eclipse STS)
does not stop at the breakpoints.

aslak hellesoy

unread,
Apr 11, 2012, 6:41:21 AM4/11/12
to cu...@googlegroups.com

Here is an example:

https://github.com/cucumber/cucumber-jvm/commit/01932dcfdf5decd1374f7a08dcec40a98fc493cb

It looks like you're doing everything right.

Aslak

> --
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
>

rsilva4

unread,
Apr 11, 2012, 6:43:14 AM4/11/12
to Cukes
I managed to sucessufully test with the datatable:

Given(~'^the following external datasources:$') { eds ->

def listEds = eds.asList(ExternalDataSource)
listEds.each { ExternalDataSource it ->
it.save()
}
assert ExternalDataSource.findAll().size() == listEds.size()
}

However, I still don't have a clue how to debug or print stuff in the
step definitions.

aslak hellesoy

unread,
Apr 11, 2012, 6:59:00 AM4/11/12
to cu...@googlegroups.com
On Wed, Apr 11, 2012 at 11:43 AM, rsilva4 <rubens...@gmail.com> wrote:
> I managed to sucessufully test with the datatable:
>
> Given(~'^the following external datasources:$') { eds ->
>
>        def listEds = eds.asList(ExternalDataSource)
>                listEds.each { ExternalDataSource it ->
>                    it.save()
>                }
>        assert ExternalDataSource.findAll().size() == listEds.size()
> }
>
> However, I still don't have a clue how to debug or print stuff in the
> step definitions.
>

Are you saying that `println("HELLO")` at the top of your step
definition prints nothing??

Aslak

> On 11 Abr, 10:10, rsilva4 <rubensilv...@gmail.com> wrote:
>> I can't find anything about this in the Groovy examples. Here what I
>> have tried:
>>
>> Given(~'^the following external datasources:$') { eds ->
>>
>>     def listEds = eds.asList(ExternalDataSource)
>>     listEds.each {
>>                 print it
>>                 ExternalDataSource.create(it);
>>         }
>>         assert ExternalDataSource.all().size() == listEds.size()
>>
>> }
>>
>> That outputs:
>>
>> | Running 1 cucumber test...
>> org.codehaus.groovy.runtime.InvokerInvocationException:
>> groovy.lang.MissingMethodException: No signature of method:
>> net.inductiva.collector.ExternalDataSource.create() is applicable for
>> argument types: (net.inductiva.collector.ExternalDataSource) values:
>> [net.inductiva.collector.ExternalDataSource : null]
>> Possible solutions: create(), merge(), read(java.io.Serializable),
>> count(), delete(), ident()
>>
>> 'print it' prints nothing, and trying to debug (using eclipse STS)
>> does not stop at the breakpoints.
>

Ruben Silva

unread,
Apr 11, 2012, 7:12:51 AM4/11/12
to cu...@googlegroups.com
Exactly. Your phrasing lead to an experiment:

import groovy.time.TimeCategory;
import cucumber.table.DataTable;
import net.inductiva.collector.ExternalDataSource;

this.metaClass.mixin (cucumber.runtime.groovy.EN)
println("HELLO")
Given(~'^the following external datasources:$') { eds ->
println("HELLO Inside Given")
}

OUTPUT:

| Server running. Browse to http://localhost:8080/collector
HELLO
| Running 1 cucumber test...
| Completed 1 cucumber test, 0 failed in 581ms

The print inside the step it's not visible.
--
Ruben

aslak hellesoy

unread,
Apr 11, 2012, 7:38:54 AM4/11/12
to cu...@googlegroups.com
On Wed, Apr 11, 2012 at 12:12 PM, Ruben Silva <rubens...@gmail.com> wrote:
> Exactly. Your phrasing lead to an experiment:
>
> import groovy.time.TimeCategory;
> import cucumber.table.DataTable;
> import net.inductiva.collector.ExternalDataSource;
>
> this.metaClass.mixin (cucumber.runtime.groovy.EN)
> println("HELLO")
> Given(~'^the following external datasources:$') { eds ->
> println("HELLO Inside Given")
> }
>
> OUTPUT:
>
> | Server running. Browse to http://localhost:8080/collector
> HELLO
> | Running 1 cucumber test...
> | Completed 1 cucumber test, 0 failed in 581ms
>
> The print inside the step it's not visible.

How do you know the step definition gets executed?
Is the output inside Eclipse's "console" window?
Can you see it if you run it all from outside eclipse (Maven, Ant,
whatever you're using)?

Aslak

aslak hellesoy

unread,
Apr 11, 2012, 7:44:36 AM4/11/12
to cu...@googlegroups.com
On Wed, Apr 11, 2012 at 12:38 PM, aslak hellesoy
<aslak.h...@gmail.com> wrote:
> On Wed, Apr 11, 2012 at 12:12 PM, Ruben Silva <rubens...@gmail.com> wrote:
>> Exactly. Your phrasing lead to an experiment:
>>
>> import groovy.time.TimeCategory;
>> import cucumber.table.DataTable;
>> import net.inductiva.collector.ExternalDataSource;
>>
>> this.metaClass.mixin (cucumber.runtime.groovy.EN)
>> println("HELLO")
>> Given(~'^the following external datasources:$') { eds ->
>> println("HELLO Inside Given")
>> }
>>
>> OUTPUT:
>>
>> | Server running. Browse to http://localhost:8080/collector
>> HELLO
>> | Running 1 cucumber test...
>> | Completed 1 cucumber test, 0 failed in 581ms
>>
>> The print inside the step it's not visible.
>
> How do you know the step definition gets executed?
> Is the output inside Eclipse's "console" window?
> Can you see it if you run it all from outside eclipse (Maven, Ant,
> whatever you're using)?
>

In IntelliJ, clicking on various nodes in the JUnit "tree" will
show/hide output so that only what was printed during a certain test
(scenario) is shown.
I'm not sure if Eclipse behaves the same, but it might. Try selecting
the root element.

Aslak

Ruben Silva

unread,
Apr 11, 2012, 10:23:20 AM4/11/12
to cu...@googlegroups.com
Yes the output inside Eclipse's "console" window. 

Just tried using grails command from shell directly same result. 

Can it be something related with my logging configuration? It seams unlikely since the first print runs. I know that my step runs because if I include some invalid assertion it fails, p.e.: assert false.

I don't get the Junit tree in eclipse because Cucumber tests are not seen like Junit tests. 

To use cucumber-jvm I follow this instructions https://github.com/hauner/grails-cucumber/wiki/Testing-Grails-with-Cucumber-and-Geb which results in adding this dependencies to my project:

../plugins/cucumber-0.2.3/lib/cucumber-core-1.0.0.RC21-SNAPSHOT.jar
../plugins/cucumber-0.2.3/lib/cucumber-groovy-1.0.0.RC21-SNAPSHOT.jar
../plugins/cucumber-0.2.3/lib/cucumber-html-0.2.1.jar
../plugins/cucumber-0.2.3/lib/gherkin-2.9.0.jar

Reading this https://github.com/hauner/grails-cucumber/blob/master/CHANGES.md we can realize that with the current release cucumber-jvm is embedded in the plugin, something to change in the next release where it will fetch cucumber-jvm as a dependency and move on to 1.0.2 version.

"Currently the plugin registers the cucumber test type only to the functional test phase." can be read in the plugin page, so no unit tests 

--
Ruben Silva

aslak hellesoy

unread,
Apr 11, 2012, 10:31:14 AM4/11/12
to cu...@googlegroups.com
On Wed, Apr 11, 2012 at 3:23 PM, Ruben Silva <rubens...@gmail.com> wrote:
> Yes the output inside Eclipse's "console" window.
>
> Just tried using grails command from shell directly same result.
>
> Can it be something related with my logging configuration? It seams unlikely
> since the first print runs. I know that my step runs because if I include
> some invalid assertion it fails, p.e.: assert false.
>
> I don't get the Junit tree in eclipse because Cucumber tests are not seen
> like Junit tests.
>

They are if you kick it off with JUnit:
https://github.com/cucumber/cucumber-jvm/blob/master/groovy/src/test/java/cucumber/runtime/groovy/RunCukesTest.java
I assume you're using the CLI runner then.

Maybe you have run into the same issue as this?
https://groups.google.com/d/msg/cukes/HJ1Ik910jPc/e5ANfEx4Pv0J

Aslak

Ruben Silva

unread,
Apr 12, 2012, 4:33:07 AM4/12/12
to cu...@googlegroups.com
Ok, we can track the why about not printing stuff here: https://github.com/hauner/grails-cucumber/issues/4

Thanks Aslak for all your attention
--
Ruben Silva
Reply all
Reply to author
Forward
0 new messages