common icon indicating copy to clipboard operation
common copied to clipboard

Support for pure Kotlin tests (needed for Kotlin Multiplatform)

Open davidvavra opened this issue 7 years ago • 10 comments
trafficstars

Kotlin now has support for multiplatform projects. Common code is written in pure Kotlin (no Java dependencies are possible) and then developer creates modules like common-jvm and common-js which can contain JVM or JS dependencies. The code in the common module should be tested and Jetbrains created annotations in kotlin.test package which are automatically translated into JUnit or JS tests. Then tests can run on all platforms with no work. More documentation here.

So currently cucumber can be used only in common-jvm or common-js modules, but not in the common module. Which means writing step definitions twice. It would be great if cucumber supported kotlin.test tests directly.

davidvavra avatar Feb 07 '18 16:02 davidvavra

Would this be a separate Kotlin implementation of Cucumber, or an addition to cucumber-jvm? I've only recently started using Kotlin myself, and we use it in combination with Java atm, so I'm not sure what would be needed to make this work. Thanks for the link; will have a look later!

mlvandijk avatar Feb 08 '18 09:02 mlvandijk

@mlvandijk Imho separate Kotlin implementation. Normally Kotlin is built on top of JVM and normal Java version can be used. But it's different for multiplatform projects.

davidvavra avatar Feb 08 '18 11:02 davidvavra

@davidvavra The link you provided states: "Multiplatform projects are a new experimental feature in Kotlin 1.2. All of the language and tooling features described in this document are subject to change in future Kotlin versions." So if someone were to create a pure Kotlin implementation of Cucumber, imho it might be best to wait until this is sorted out in Kotlin to prevent rework.

mlvandijk avatar Feb 09 '18 07:02 mlvandijk

A Kotlin implementation of Cucumber would be fantastic!

Writing a new Cucumber implementation from scratch is a considerable amount of work. There are several libraries to implement:

  • Gherkin Parser (unless you run an existing gherkin cli/exe)
  • Cucumber Expressions (unless you only want to support RegExp)
  • Tag Expressions
  • Language-specific DSL for step definitions and hooks
  • Runtime/execution engine

Would you be interested in (and able to) kick this off @davidvavra?

aslakhellesoy avatar Feb 10 '18 20:02 aslakhellesoy

That looks like a lot of work. I agree with @mlvandijk that the feature is still experimental and we should probably wait a while until it's more stable. But it's good to have an open issue and track progress/gather interest. I'm not interested in kicking off the implementation, but maybe I can help with some smaller tasks.

davidvavra avatar Feb 12 '18 12:02 davidvavra

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

stale[bot] avatar Apr 13 '18 12:04 stale[bot]

This should get easiers when we get further through the roadmap.

aslakhellesoy avatar Jul 05 '18 21:07 aslakhellesoy

Is anyone still interested in tackling this?

mattwynne avatar Jun 09 '21 13:06 mattwynne

It might be easier to port instead of rewriting. If it is an independent implementation, then both implementations have to be maintained, but if the old is ported to Kotlin Multiplatform then it can be used for both Java (JVM) testing and Kotlin Multiplatform testing.

The approach I would take would be:

  1. Port the Java code to Kotlin
  2. Convert from Maven to Gradle (there's a lot more resources out there on KMP using Gradle than with Maven)
  3. Replace libraries with ones that support Kotlin Multiplatform
  4. Switch any IO to using something like okio
  5. Enable Kotlin Mulitplatform
  6. Fix errors for code that was still using JVM specific classes

This could even be done would module at a time.

mkrussel77 avatar Mar 21 '22 17:03 mkrussel77

if the old is ported to Kotlin Multiplatform then it can be used for both Java (JVM) testing and Kotlin Multiplatform testing.

Unfortunately this adds a dependency on the Kotlin standard library.

This is a non-trivial piece of complexity added to every project that uses Cucumber.

Cucumber is used as a testing library. This additional complexity may make a test run less representative. So generally speaking we try to avoid introducing additional depencies (or at the very least shade then).

mpkorstanje avatar Mar 22 '22 00:03 mpkorstanje