Skip to content

Add Cucumber Kotlin Junit5 example #2999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
271b1a3
first commit
jit3pam May 16, 2025
8ca70be
add examples for Kotlin
jit3pam May 16, 2025
6311992
add examples for Kotlin date_calculator.feature
jit3pam May 16, 2025
b413ea6
Merge branch 'cucumber:main' into cucumber-kotlin-testng-examples
jit3pam May 16, 2025
2cbc758
add implementations for Kotlin date_calculator.feature
jit3pam May 16, 2025
27d061b
remove tag from RunCucumberTest.kt
jit3pam May 16, 2025
b3216e0
Merge remote-tracking branch 'origin/cucumber-kotlin-testng-examples'…
jit3pam May 16, 2025
5683424
Merge branch 'cucumber:main' into cucumber-kotlin-testng-examples
jit3pam May 17, 2025
785035c
Update examples/calculator-kotlin-testng/pom.xml
jit3pam May 19, 2025
326c3c6
restore pom.xml in examples
jit3pam May 19, 2025
698675f
update examples to use junit5
jit3pam May 21, 2025
50f08a4
Merge branch 'cucumber:main' into cucumber-kotlin-testng-examples
jit3pam May 21, 2025
194ab02
update dependencies in pom.xml
jit3pam May 21, 2025
7684f62
update dependencies in pom.xml, and change .* imports to explicit imp…
jit3pam May 21, 2025
ca7df3c
first commit
jit3pam May 16, 2025
0136a44
add examples for Kotlin
jit3pam May 16, 2025
b0db4b4
add examples for Kotlin date_calculator.feature
jit3pam May 16, 2025
7f46e5f
add implementations for Kotlin date_calculator.feature
jit3pam May 16, 2025
b954cfc
remove tag from RunCucumberTest.kt
jit3pam May 16, 2025
e6fba37
Update examples/calculator-kotlin-testng/pom.xml
jit3pam May 19, 2025
8125d05
restore pom.xml in examples
jit3pam May 19, 2025
8c1d5cf
update examples to use junit5
jit3pam May 21, 2025
450409c
update dependencies in pom.xml
jit3pam May 21, 2025
8390b15
update dependencies in pom.xml, and change .* imports to explicit imp…
jit3pam May 21, 2025
0a28103
restore the xml in examples
jit3pam May 21, 2025
6e8a56c
restore the xml in examples
jit3pam May 21, 2025
3478532
update the tags in examples/pom.xml
jit3pam May 21, 2025
6d15200
Merge remote-tracking branch 'origin/main' into cucumber-kotlin-testn…
mpkorstanje May 23, 2025
1f83c0b
[All] Set version to 7.23.0-SNAPSHOT
mpkorstanje May 23, 2025
b253d5e
Harmonize
mpkorstanje May 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/calculator-java-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<artifactId>calculator-java-cli</artifactId>
<packaging>jar</packaging>
<name>Examples: Calculator - Annotations - CLI</name>
<name>Examples: Calculator - Java - Annotations - CLI</name>

<properties>
<project.Automatic-Module-Name>io.cucumber.examples.calculator</project.Automatic-Module-Name>
Expand Down
2 changes: 1 addition & 1 deletion examples/calculator-java-junit4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<artifactId>calculator-java-junit4</artifactId>
<packaging>jar</packaging>
<name>Examples: Calculator - Annotations - Junit4</name>
<name>Examples: Calculator - Java - Annotations - Junit4</name>

<properties>
<project.Automatic-Module-Name>io.cucumber.examples.calculator</project.Automatic-Module-Name>
Expand Down
44 changes: 27 additions & 17 deletions examples/calculator-java-junit5/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -9,10 +10,10 @@

<artifactId>calculator-java-junit5</artifactId>
<packaging>jar</packaging>
<name>Examples: Calculator - Annotations - Junit 5</name>
<name>Examples: Calculator - Java - Annotations - Junit 5</name>

<properties>
<project.Automatic-Module-Name>io.cucumber.calculator</project.Automatic-Module-Name>
<project.Automatic-Module-Name>io.cucumber.examples.calculator</project.Automatic-Module-Name>
</properties>

<dependencyManagement>
Expand All @@ -27,7 +28,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.1</version>
<version>5.12.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -38,6 +39,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-bom</artifactId>
<version>3.27.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -57,11 +65,6 @@
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console</artifactId>
Expand All @@ -72,6 +75,11 @@
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -106,14 +114,16 @@
</goals>
<configuration>
<target unless="maven.test.skip">
<echo message="Running JUnit Platform CLI" />
<java classname="org.junit.platform.console.ConsoleLauncher" fork="true" failonerror="true" newenvironment="true" maxmemory="512m" classpathref="maven.test.classpath">
<arg value="--include-engine" />
<arg value="cucumber" />
<arg value="--scan-classpath" />
<arg value="${project.build.testOutputDirectory}" />
<arg value="--reports-dir" />
<arg value="${project.build.directory}/cucumber-reports" />
<echo message="Running JUnit Platform CLI"/>
<java classname="org.junit.platform.console.ConsoleLauncher" fork="true"
failonerror="true" newenvironment="true" maxmemory="512m"
classpathref="maven.test.classpath">
<arg value="--include-engine"/>
<arg value="cucumber"/>
<arg value="--scan-classpath"/>
<arg value="${project.build.testOutputDirectory}"/>
<arg value="--reports-dir"/>
<arg value="${project.build.directory}/cucumber-reports"/>
</java>
</target>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class DateStepDefinitions {

Expand All @@ -25,6 +25,6 @@ public void I_ask_if_date_is_in_the_past(Date date) {

@Then("^the result should be (yes|no)$")
public void the_result_should_be(String expectedResult) {
assertEquals(expectedResult, result);
assertThat(result).isEqualTo(expectedResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class RpnCalculatorSteps {

Expand Down Expand Up @@ -66,7 +66,7 @@ public void I_press(String what) {

@Then("the result is {int}")
public void the_result_is(double expected) {
assertEquals(expected, calc.value());
assertThat(calc.value()).isEqualTo(expected);
}

@Given("the previous entries:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class ShoppingSteps {

Expand All @@ -28,7 +28,7 @@ public void i_pay(int amount) {

@Then("my change should be {}")
public void my_change_should_be_(int change) {
assertEquals(-calc.value().intValue(), change);
assertThat(-calc.value().intValue()).isEqualTo(change);
}

static class Grocery {
Expand Down
2 changes: 1 addition & 1 deletion examples/calculator-java-testng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<artifactId>calculator-java-testng</artifactId>
<packaging>jar</packaging>
<name>Examples: Calculator - Annotations - TestNG</name>
<name>Examples: Calculator - Java - Annotations - TestNG</name>

<properties>
<project.Automatic-Module-Name>io.cucumber.examples.calculator</project.Automatic-Module-Name>
Expand Down
2 changes: 1 addition & 1 deletion examples/calculator-java8-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<artifactId>calculator-java8-cli</artifactId>
<packaging>jar</packaging>
<name>Examples: Calculator - Lambda - CLI</name>
<name>Examples: Calculator - Java - Lambda - CLI</name>

<properties>
<project.Automatic-Module-Name>io.cucumber.examples.calculator</project.Automatic-Module-Name>
Expand Down
4 changes: 4 additions & 0 deletions examples/calculator-kotlin-junit5/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.settings
/.classpath
/.project
/test-output/
158 changes: 158 additions & 0 deletions examples/calculator-kotlin-junit5/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.cucumber</groupId>
<artifactId>examples</artifactId>
<version>7.23.0-SNAPSHOT</version>
</parent>

<artifactId>calculator-kotlin-junit5</artifactId>
<packaging>jar</packaging>
<name>Examples: Calculator - Kotlin - Annotations - Junit 5</name>

<properties>
<kotlin.code.style>official</kotlin.code.style>
<project.Automatic-Module-Name>io.cucumber.examples.calculator</project.Automatic-Module-Name>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.12.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-bom</artifactId>
<version>2.1.21</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>2.1.21</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<!-- Work around. Surefire does not include enough information to disambiguate between different
examples. -->
<configurationParameters>
cucumber.junit-platform.naming-strategy=long
</configurationParameters>
</properties>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<!-- Work around. Surefire does not use JUnits Test Engine discovery functionality.

Alternatively use the JUnit Platform Suite Engine.
-->
<id>cli-test</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target unless="maven.test.skip">
<echo message="Running JUnit Platform CLI"/>
<java classname="org.junit.platform.console.ConsoleLauncher" fork="true"
failonerror="true" newenvironment="true" maxmemory="512m"
classpathref="maven.test.classpath">
<arg value="--include-engine"/>
<arg value="cucumber"/>
<arg value="--scan-classpath"/>
<arg value="${project.build.testOutputDirectory}"/>
<arg value="--reports-dir"/>
<arg value="${project.build.directory}/cucumber-reports"/>
</java>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.cucumber.examples.calaculator

import java.time.LocalDate
import java.util.*

class DateCalculator(private val now: LocalDate) {

fun isDateInThePast(date: LocalDate): String {
return if (date.isBefore(now)) "yes" else "no"
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.cucumber.examples.calaculator

class RpnCalculator {
private val stack: ArrayDeque<Number> = ArrayDeque()

private val OPS = setOf("+", "-", "*", "/")

fun push(arg: Any) {
if (arg in OPS) {
val y = stack.removeLast()
val x = if (stack.isEmpty()) 0 else stack.removeLast()
val valResult = when (arg) {
"-" -> x.toDouble() - y.toDouble()
"+" -> x.toDouble() + y.toDouble()
"*" -> x.toDouble() * y.toDouble()
"/" -> x.toDouble() / y.toDouble()
else -> throw IllegalArgumentException("Unknown operation $arg")
}
push(valResult)
} else {
stack.addLast(arg as Number)
}
}

fun peek(): Number? = stack.lastOrNull()

fun clear() = stack.clear()
}

Loading