Reputation: 22307
I want to use the kotlin native step definitions like:
package cucumber.runtime.kotlin.test;
...
class LambdaStepdefs : En {
init {
Before { scenario: Scenario ->
assertNotSame(this, lastInstance)
lastInstance = this
}
Given("^this data table:$") { peopleTable: DataTable ->
val people = peopleTable.asList(Person::class.java)
assertEquals("Aslak", people[0].first)
assertEquals("Hellesøy", people[0].last)
}
Where Given
takes a function and is not an annotation. I do not want to use the Java-style like @Given("blabla") void blabla() { ... }
.
I tried to import the package from the example:
package vc.capper.cutest;
import cucumber.runtime.kotlin.test
class SomeStepDefs
{
Given("blabla") {
}
}
But the package kotlin
can not be found in cucumber.runtime
.
I thought the io.cucumber:cucumber-jvm
(artifact)[https://github.com/cucumber/cucumber-jvm/blob/master/pom.xml] comes with cucumber-kotlin-java8
, but it either does not or it does not contain said Given
.
This is an excerpt from my pom.xml
-- somethign is missing, I guess, but what?
Prelude:
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.1.2-2</kotlin.version>
<spring-boot.version>1.5.7.RELEASE</spring-boot.version>
<cucumber.version>2.0.1</cucumber.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
...
</dependencyManagement>
Dependencies:
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>${cucumber.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre8</artifactId>
<version>${kotlin.version}</version>
</dependency>
...
</dependencies>
Update and clarification:
The packages that seem to be missing are cucumber.runtime.kotlin
and cucumber.api.java8.En
as you can see from the IntelliJ screenshot:
Also you can see the list of actual dependencies the project uses:
Upvotes: 2
Views: 1107
Reputation: 3026
Change <artifactId>cucumber-jvm</artifactId>
to <artifactId>cucumber-java8</artifactId>
to use lambda style definitions.
Note there currently is no native Kotlin implementation of cucumber.
Also, the cucumber-kotlin-java8
you are referring to is an example of how to use Cucumber-java8 with Kotlin.
In addition, you'll need to extend the En
interface.
Upvotes: 0
Reputation: 33441
It looks like that Given
is not a Kotlin specific DSL / method. It is a part of cucumber.api.java8.En
. All you have to do is to extend your class from it:
package vc.capper.cutest;
import cucumber.runtime.kotlin.test
import cucumber.api.java8.En
class SomeStepDefs : En {
Given("blabla") {
...
}
}
Upvotes: 3