Support step definitions written in Kotlin
See original GitHub issueSummary
Cucumber currently supports Kotlin by using Java Annotations or Lambda based step definitions. This works because Java and Kotlin can interoperate. This does however fails to leverage some of the advantages of Kotlin (#1554, #1520). So a Kotlin backend would be most useful.
Update:
The approach describe below will not work in the future because we are aiming for a design where step definitions must be discoverable without instantiating the glue class. For this reason we are deprecating cucumber-java8
(https://github.com/cucumber/cucumber-jvm/issues/2174) and this design was patterned on that. As a replacement for cucumber-java8
we are considering cucumber-lambda
(https://github.com/cucumber/cucumber-jvm/issues/2279). This may or may not make this ticket obsolete.
Goals
-
Implement a Kotlin backend that supports step definitions, hooks, data table and parameter type declaration.
-
Avoid the duplication of method name and step definition common when using annotation based step definitions. Example:
Given("a step definition")
public void given_a_step_definition() {}
-
Use Kotlin primitives and types everywhere. This should include Cucumber expressions, parameter types, data table types,
DataTable
andDocString
. -
Generate Kotlin step definitions
Step definitions
class StepDefinitions(belly: Belly) : En {
init {
Given("there are {int} cukes in my belly"){ cukes : Int ->
belly.setCukes(cukes)
}
When("^I eat ([0-9]) cukes$") { cukes : Int ->
belly.addCukes(cukes)
}
}
}
En
would be implement as a class with members for various keywords and other glue (see java8 equivalent).
interface Test {
fun Given(expression: String, f: Function<Unit>) {
//Register with thread local as in Java 8
}
... other key words
}
Note that Function
has subtypes that support up to up to 22 parameters. After that it becomes a varg and we can no longer user f.javaClass.methods[1].genericParameterTypes
to work out what the the types were. As a result Cucumber won’t be able to convert arguments automatically when using regular rather then Cucumber expressions. This is a reasonable drawback for wanting to use 22+ parameters.
Steps to take
- Implement a
KotlinBackendProviderService
andKotlinBackend
andKotlinStepDefinition
for a single annotation. For examples seeJava8**
equivalents in thejava8
module. - Experiment to see how the interop works
- Implement everything else (sorry about the draw-the-rest-of-the-owl, I don’t know what or how yet).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:20 (9 by maintainers)
Top GitHub Comments
This looks promising:
The plumbing:
Unfortunately not. See: https://github.com/cucumber/cucumber-jvm/issues/1829#issuecomment-558640666