[JVM] Java 8 support

87 views
Skip to first unread message

aslak hellesoy

unread,
Dec 11, 2014, 8:34:06 AM12/11/14
to Cucumber Users
Hi everyone,

Wouldn't it be nice to use Java 8 closures for step definitions and hooks?

        Given("I have (\\d+) cukes in my (.*)", (Integer cukes, String what) -> {
            assertEquals(42, cukes.intValue());
            assertEquals("belly", what);
        });

Well, we're pretty close to that on the java8 branch of cucumber-jvm.

There is one annoying thing with the current implementation - we don't have state isolation yet. What this means is that several scenarios won't have isolated state. This is obviously no good, so I'm hoping the community can help.

I like illustrating problems with a failing scenario, and here it is:


This lives on the java8-state branch.

Any suggestions how we can deal with this? Any smart hacks? Should we design the API differently?

Aslak

aslak hellesoy

unread,
Dec 12, 2014, 8:23:44 AM12/12/14
to Cucumber Users
I came up with a fix for Java 8 lambda stepdefs, and this is now on the master branch. You'll have it in the next release, but you can already try out 1.2.1-SNAPSHOT. Here is an example:


The implementation is using some clever tricks and unofficial APIs, so this will only work on Oracle and Open JDK.

Would love some feedback on this!

Aslak

Rakesh

unread,
Dec 13, 2014, 6:14:50 AM12/13/14
to cu...@googlegroups.com
Hi,

I would like to point out that right now Android only support Java api 6.

Writing cucumber code that runs on the device (ie android
instrumentation tests as opposed to using appium for example),
probably won't work.

R
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Aslak Hellesøy

unread,
Dec 13, 2014, 6:37:43 AM12/13/14
to cu...@googlegroups.com

On Saturday, 13 December 2014 at 11:14, Rakesh wrote:

Hi,

I would like to point out that right now Android only support Java api 6.

Writing cucumber code that runs on the device (ie android
instrumentation tests as opposed to using appium for example),
probably won't work.

Yes we know that, so Android will have to use the annotated method style. The old style isn't going away.

Sorry fir any confusion

Anderson Fernandes

unread,
Jun 26, 2015, 9:19:46 PM6/26/15
to cu...@googlegroups.com
Is it possible to use DataTable with lambda expressions?

Anderson Fernandes

unread,
Jun 26, 2015, 9:19:47 PM6/26/15
to cu...@googlegroups.com
I'd like to point that there's a bug while counting the parameters for the Java8StepDefinition.

The "parameterInfos" is being populated with the types from the lambda expression but this information is not being used in the "getParameterCount" method.

This means lambda expressions will not work for DataTable.

Anderson

On Friday, 12 December 2014 13:23:44 UTC, Aslak Hellesøy wrote:
Reply all
Reply to author
Forward
0 new messages