12

I have the following test class:

import org.scalatest.FunSuite

@RunWith(classOf[JUnitRunner])
class NodeScalaSuite extends FunSuite {

With this test method:

  test("Now doesn't terminate future that's not done") {
    val testFuture: Future[Int] = Future{
      wait(1000)
      10
    }
    assertThrows[NoSuchElementException]{
      testFuture.now
    }
  }

I am getting this error:

not found: value assertThrows

I looked over the ScalaTest documentation from here http://doc.scalatest.org/3.0.0/#org.scalatest.FunSuite and the code that's similar to mine seems to work fine.

What's the issue?

bsky
  • 19,326
  • 49
  • 155
  • 270

1 Answers1

23

I also just faced this problem - but as mentioned in the comments it was down to the version of scala test I was using. assertThrows was not introduced until after 2.2.6 - upgrading to 3.0.0 (if you can) will make it possible: See older version of the referenced docs here: http://doc.scalatest.org/2.2.6/#org.scalatest.FunSuite

If you cannot upgrade, the previous way to assert exceptions was using the intercept method:

  test("Invoking head on an empty Set should produce NoSuchElementException") {
    intercept[NoSuchElementException] {
      Set.empty.head
    }
  }
rhinds
  • 9,976
  • 13
  • 68
  • 111