sbt / sbt-jupiter-interface

Implementation of sbt's test interface for JUnit 5's Jupiter module
Apache License 2.0
32 stars 17 forks source link

Support JUnit 3 TestSuite #89

Open eed3si9n opened 1 month ago

eed3si9n commented 1 month ago

I understand if the original intention of the fix for @Suite was to only fix JUnit 4 suites. I only wish to provide some feedback about other cases.

steps

// src/test/MathTest.scala
// This is a definition of a JUnit 3 test case. Many of these test cases will be "dynamically" collected into a JUnit 3 `TestSuite` and run.

class MathTest(op1: Int, op2: Int, res: Int) extends TestCase(s"$op1 + $op2 = $res") {
  final override def runTest(): Unit = {
    assertEquals(res, op1 + op2)
  }
}
// src/test/MathSuite.scala

class MathSuite extends TestCase

object MathSuite {
  // This is essentially a Scala 2.12+ hack, where methods on the companion object produce static forwarders on the class.
  // This is the Scala equivalent of the JUnit 3 convention public static Test suite() { ... }
  def suite(): Test = {
    val s = new TestSuite("MathSuite")
    s.addTest(new MathTest(1, 2, 3))
    s.addTest(new MathTest(2, 3, 4))
    s
  }
}

problem

It still produces:

[error] java.lang.RuntimeException: Test class MathTest is not enclosed by MathSuite

notes

The JUnit 3 TestSuite is still not fixed by https://github.com/sbt/sbt-jupiter-interface/pull/87 (I did a publishLocal).

Originally posted by @vasilmkd in https://github.com/sbt/sbt-jupiter-interface/issues/87#issuecomment-2254618861

vasilmkd commented 1 month ago

Thanks for opening this ticket!

vasilmkd commented 1 month ago

An additional detail to this ticket, "org.junit.vintage" % "junit-vintage-engine" % JupiterKeys.junitVintageVersion.value % Test is required as a dependency for reproducing the described problem.