Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not found: value assertThrows

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?

like image 695
octavian Avatar asked Aug 28 '16 18:08

octavian


1 Answers

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
    }
  }
like image 140
rhinds Avatar answered Oct 21 '22 09:10

rhinds