-
Notifications
You must be signed in to change notification settings - Fork 43
Closed
Description
JUnit supports running tests with the same fully-qualified name several times.
It can be achieved by using some non-standard built-in runners or some custom runners.
Here is the easiest example of such test using org.junit.runners.Suite
build.sbt
name := "junit-with-sbt"
version := "0.1"
scalaVersion := "2.13.6"
// NOTE: by default junit-interface ignores `org.junit.runners.Suite`, we need to disable it
Test / testOptions += Tests.Argument( "--verbosity=3", "--ignore-runners=")
libraryDependencies += ("com.novocode" % "junit-interface" % "0.11" % Test).withSources()
MyCompositeTest.scala
:
package example
import junit.framework.{TestCase, TestSuite}
import org.junit.Assert.fail
import org.junit.runner.RunWith
import org.junit.runners.Suite.SuiteClasses
@RunWith(classOf[org.junit.runners.Suite])
@SuiteClasses(Array(
classOf[example.MyActualTest],
classOf[example.MyActualTest],
classOf[example.MyActualTest]
))
class MyCompositeTest extends TestSuite
class MyActualTest extends TestCase {
def test1_Success(): Unit = {
println("running success test")
}
def test2_Failed(): Unit = {
println("running failed test")
fail("some reason")
}
}
Note that in practice, those tests can have different contexts but have the same name.
Intellij IDEA, for example, successfully runs such tests:
(note, that in total, there were 6 tests run.
And thisis what testOnly example.MyCompositeTest
outputs:
lefou
Metadata
Metadata
Assignees
Labels
No labels