Skip to content
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

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

Open
SamirTalwar opened this issue Jun 7, 2021 · 0 comments

Comments

@SamirTalwar
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant