Skip to content

🧹 chore: use JUnit 5 #400

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 1 commit into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH
----
## [Unreleased] (In Git)

📢 As of Cucumber JVM 7.24, `cucumber-junit` (JUnit 4) is deprecated in favour of `cucumber-junit-platform-engine`
(JUnit 5). Users are strongly encouraged to use the latter.

📖 Read the "Run" section in [Basic usage](docs/usage.md) to see examples of Cucumber + JUnit 5.

ℹ️ `cucumber-junit-platform-engine` 7.26+ is required when using SBT, lower versions will run Cucumber tests twice and
fail with runtime errors due to [a bug in the SBT/JUnit 5 interface](https://github.com/sbt/sbt-jupiter-interface/issues/142).
Thanks @mpkorstanje for providing a [workaround in Cucumber JVM](https://github.com/cucumber/cucumber-jvm/pull/3023)!

### Added

- [Documentation] Integration with JUnit 5
- Add example project with JUnit 5

### Changed

- [Core] Update `cucumber-core` dependency to [7.26.0](https://github.com/cucumber/cucumber-jvm/blob/main/CHANGELOG.md)
- [Internal] Update integration tests to use JUnit 5
- Drop support of Scala 2.12 in example test projects

### Deprecated

### Removed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ See: https://cucumber.io/support
## Compatibility matrix

Cucumber Scala has a different release cycle than other Cucumber projects that you might use
(like _cucumber-junit_).
(like _cucumber-junit-platform-engine_).

As a rule of thumb, you can assume that latest version of Cucumber Scala targets the latest version
of Cucumber Core projects.
Expand Down Expand Up @@ -44,7 +44,7 @@ The table below shows the compatible versions:
- [Hooks](docs/hooks.md)
- [Transformers](docs/transformers.md)
- [Default Jackson DataTable Transformer](docs/default_jackson_datatable_transformer.md)
- [Example project](examples/README.md)
- [Example project](examples/examples-junit5/README.md)
- [Reference documentation for Java](https://docs.cucumber.io/docs/cucumber/)
- [Changelog](CHANGELOG.md)

Expand Down
64 changes: 48 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ scalaVersion := scala213

// Library versions

val cucumberVersion = "7.23.0"
val cucumberVersion = "7.26.0"
val jacksonVersion = "2.19.1"
val mockitoScalaVersion = "1.17.45"
val junitVersion = "4.13.2"
val junitJupiterVersion = "5.13.3"
val junitPlatformVersion = "1.13.3"

// Projects and settings

lazy val commonSettings = Seq(
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test,
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => ScalacOptions.scalacOptions212
Expand All @@ -58,6 +59,13 @@ lazy val commonSettings = Seq(
}
)

lazy val junit4SbtSupport = Seq(
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test
)
lazy val junit5SbtSupport = Seq(
libraryDependencies += "com.github.sbt.junit" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test
)

lazy val root = (project in file("."))
.settings(commonSettings)
.settings(
Expand All @@ -68,19 +76,21 @@ lazy val root = (project in file("."))
integrationTestsCommon.projectRefs ++
integrationTestsJackson.projectRefs ++
integrationTestsPicoContainer.projectRefs ++
examples.projectRefs: _*
examplesJunit4.projectRefs ++
examplesJunit5.projectRefs: _*
)

// Main project
lazy val cucumberScala = (projectMatrix in file("cucumber-scala"))
.settings(commonSettings)
.settings(junit5SbtSupport)
.settings(
name := "cucumber-scala",
libraryDependencies ++= Seq(
"io.cucumber" % "cucumber-core" % cucumberVersion,
// Users have to provide it (for JacksonDefaultDataTableTransformer)
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided,
"junit" % "junit" % junitVersion % Test,
"org.junit.jupiter" % "junit-jupiter" % junitJupiterVersion % Test,
("org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test)
.cross(CrossVersion.for3Use2_13)
),
Expand Down Expand Up @@ -127,11 +137,13 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala"))
lazy val integrationTestsCommon =
(projectMatrix in file("integration-tests/common"))
.settings(commonSettings)
.settings(junit5SbtSupport)
.settings(
name := "integration-tests-common",
libraryDependencies ++= Seq(
"junit" % "junit" % junitVersion % Test,
"io.cucumber" % "cucumber-junit" % cucumberVersion % Test
"org.junit.jupiter" % "junit-jupiter" % junitJupiterVersion % Test,
"org.junit.platform" % "junit-platform-suite" % junitPlatformVersion % Test,
"io.cucumber" % "cucumber-junit-platform-engine" % cucumberVersion % Test
),
publishArtifact := false
)
Expand All @@ -141,11 +153,13 @@ lazy val integrationTestsCommon =
lazy val integrationTestsJackson =
(projectMatrix in file("integration-tests/jackson"))
.settings(commonSettings)
.settings(junit5SbtSupport)
.settings(
name := "integration-tests-jackson",
libraryDependencies ++= Seq(
"junit" % "junit" % junitVersion % Test,
"io.cucumber" % "cucumber-junit" % cucumberVersion % Test,
"org.junit.jupiter" % "junit-jupiter" % junitJupiterVersion % Test,
"org.junit.platform" % "junit-platform-suite" % junitPlatformVersion % Test,
"io.cucumber" % "cucumber-junit-platform-engine" % cucumberVersion % Test,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Test
),
publishArtifact := false
Expand All @@ -156,11 +170,13 @@ lazy val integrationTestsJackson =
lazy val integrationTestsPicoContainer =
(projectMatrix in file("integration-tests/picocontainer"))
.settings(commonSettings)
.settings(junit5SbtSupport)
.settings(
name := "integration-tests-picocontainer",
libraryDependencies ++= Seq(
"junit" % "junit" % junitVersion % Test,
"io.cucumber" % "cucumber-junit" % cucumberVersion % Test,
"org.junit.jupiter" % "junit-jupiter" % junitJupiterVersion % Test,
"org.junit.platform" % "junit-platform-suite" % junitPlatformVersion % Test,
"io.cucumber" % "cucumber-junit-platform-engine" % cucumberVersion % Test,
"io.cucumber" % "cucumber-picocontainer" % cucumberVersion % Test
),
publishArtifact := false
Expand All @@ -169,8 +185,9 @@ lazy val integrationTestsPicoContainer =
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212))

// Examples project
lazy val examples = (projectMatrix in file("examples"))
lazy val examplesJunit4 = (projectMatrix in file("examples/examples-junit4"))
.settings(commonSettings)
.settings(junit4SbtSupport)
.settings(
name := "scala-examples",
libraryDependencies ++= Seq(
Expand All @@ -180,7 +197,22 @@ lazy val examples = (projectMatrix in file("examples"))
publishArtifact := false
)
.dependsOn(cucumberScala % Test)
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212))
.jvmPlatform(scalaVersions = Seq(scala3, scala213))

lazy val examplesJunit5 = (projectMatrix in file("examples/examples-junit5"))
.settings(commonSettings)
.settings(junit5SbtSupport)
.settings(
name := "scala-examples",
libraryDependencies ++= Seq(
"io.cucumber" % "cucumber-junit-platform-engine" % cucumberVersion % Test,
"org.junit.jupiter" % "junit-jupiter" % junitJupiterVersion % Test,
"org.junit.platform" % "junit-platform-suite" % junitPlatformVersion % Test
),
publishArtifact := false
)
.dependsOn(cucumberScala % Test)
.jvmPlatform(scalaVersions = Seq(scala3, scala213))

// Version policy check

Expand All @@ -204,12 +236,12 @@ releaseProcess := Seq[ReleaseStep](
runTest,
setReleaseVersion,
// the 2 following steps are part of the Cucumber release process
//commitReleaseVersion,
//tagRelease,
// commitReleaseVersion,
// tagRelease,
releaseStepCommandAndRemaining("publishSigned"),
releaseStepCommand("sonatypeBundleRelease"),
setNextVersion
// the 2 following steps are part of the Cucumber release process
//commitNextVersion,
//pushChanges
// commitNextVersion,
// pushChanges
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.cucumber.scala

import io.cucumber.core.backend._
import org.junit.Assert.{assertEquals, assertTrue}
import org.junit.Test
import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
import org.junit.jupiter.api.Test

import scala.annotation.nowarn
import scala.util.Try
Expand Down Expand Up @@ -339,8 +339,8 @@ class ScalaDslStepsTest {
// The result is different between Scala versions, that's why we don't check it precisely
// assertEquals("$anonfun$can_provide_location_of_step$1", matched.getMethodName)
assertTrue(
s"${matched.getClassName} did not contain $exceptionClassName",
matched.getClassName.contains(exceptionClassName)
matched.getClassName.contains(exceptionClassName),
s"${matched.getClassName} did not contain $exceptionClassName"
)
assertEquals(exceptionFile, matched.getFileName)
assertEquals(exceptionLine, matched.getLineNumber)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.cucumber.scala

import io.cucumber.core.backend._
import org.junit.Assert.{assertEquals, assertTrue}
import org.junit.Test
import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
import org.junit.jupiter.api.Test

import scala.annotation.nowarn
import scala.util.Try
Expand Down Expand Up @@ -338,8 +338,8 @@ class ScalaDslStepsTest {

// The result is different between Scala versions, that's why we don't check it precisely
assertTrue(
s"$matched did not contain $exceptionClassName",
matched.toString.contains(exceptionClassName)
matched.toString.contains(exceptionClassName),
s"$matched did not contain $exceptionClassName"
)
assertEquals(exceptionFile, matched.getFileName)
assertEquals(exceptionLine, matched.getLineNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import io.cucumber.scala.steps.errors.incorrectclasshooks.IncorrectClassHooksDef
import io.cucumber.scala.steps.errors.staticclasshooks.StaticClassHooksDefinition
import io.cucumber.scala.steps.objects.StepsInObject
import io.cucumber.scala.steps.traits.StepsInTrait
import org.junit.Assert.{assertEquals, assertTrue, fail}
import org.junit.{Before, Test}
import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue, fail}
import org.junit.jupiter.api.{BeforeEach, Test}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito._

Expand All @@ -30,7 +30,7 @@ class ScalaBackendTest {

private var backend: ScalaBackend = _

@Before
@BeforeEach
def beforeEach(): Unit = {
// Reset mocks
reset(fakeGlue, fakeLookup, fakeContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package io.cucumber.scala

import io.cucumber.datatable.DataTable
import io.cucumber.scala.ScalaDslDataTableTypeTest.{Author, Cell, GroupOfAuthor}
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

import scala.jdk.CollectionConverters._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.cucumber.scala

import io.cucumber.core.backend._
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class ScalaDslDefaultDataTableCellTransformerTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.cucumber.scala

import io.cucumber.core.backend._
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

import scala.jdk.CollectionConverters._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.cucumber.scala

import io.cucumber.core.backend._
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class ScalaDslDefaultParameterTransformerTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.cucumber.scala

import io.cucumber.core.backend._
import org.junit.Test
import org.junit.jupiter.api.Test

import scala.annotation.nowarn

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.cucumber.scala

import io.cucumber.core.backend._
import org.junit.Assert.{assertEquals, assertTrue}
import org.junit.{Before, Test}
import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
import org.junit.jupiter.api.{BeforeEach, Test}
import org.mockito.Mockito.mock

import java.util.concurrent.atomic.AtomicBoolean
Expand All @@ -19,7 +19,7 @@ class ScalaDslHooksTest {
invoked.set(true)
}

@Before
@BeforeEach
def beforeEach(): Unit = {
// Reset the invoked flag
invoked.set(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package io.cucumber.scala

import io.cucumber.core.backend._
import io.cucumber.scala.ScalaDslParameterTypeTest.Point
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

import scala.jdk.CollectionConverters._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import io.cucumber.cucumberexpressions.{
ParameterTypeRegistry,
TypeReference
}
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

import scala.jdk.CollectionConverters._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.cucumber.scala

import io.cucumber.datatable.DataTable
import org.junit.Assert.{assertEquals, assertTrue}
import org.junit.Test
import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
import org.junit.jupiter.api.Test

import java.lang.reflect.{ParameterizedType => JavaParameterizedType}
import java.util.{List => JavaList, Map => JavaMap}
Expand Down
Loading
Loading