scalatest / scalatestplus-junit

ScalaTest + JUnit provides integration support between ScalaTest and JUnit.
Apache License 2.0
7 stars 10 forks source link

Throwing a Scala `object` does not fail the test, using the JUnit runner #25

Open SamirTalwar opened 3 years ago

SamirTalwar commented 3 years ago

When I run this test using Gradle and the JUnit runner, it succeeds, despite the exception.

package foo

import org.junit.runner.RunWith
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class StrangeTestRunnerBehaviorSpec extends AnyFlatSpec with Matchers {
  "thing" should "not throw" in {
    throw StrangeTestRunnerBehaviorSpec.SomethingBadHappened
  }
}

object StrangeTestRunnerBehaviorSpec {
  object SomethingBadHappened extends RuntimeException
}

Changing SomethingBadHappened to a class and constructing it with new makes it fail.

The test fails correctly when running using SBT, without @RunWith.

I would expect this test to fail regardless of the runner used.

I tested this with ScalaTest 3.2.9, JUnit 4.13, and ScalaTest + JUnit 3.2.9.0.

Thanks to all of the maintainers of ScalaTest for your hard work!