Skip to content

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

@SamirTalwar

Description

@SamirTalwar

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions