Not Found: value assertThrows

I have the following test class:

import org.scalatest.FunSuite @RunWith(classOf[JUnitRunner]) class NodeScalaSuite extends FunSuite { 

Using this testing method:

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

I get this error:

 not found: value assertThrows 

I looked at the ScalaTest documentation here http://doc.scalatest.org/3.0.0/#org.scalatest.FunSuite , and code similar to mine seems to work fine.

What is the problem?

+6
source share
1 answer

I also ran into this problem, but as mentioned in the comments, it was not up to the scala test version that I used. assertThrows not introduced until 2.2.6 - updating to 3.0.0 (if possible) will allow: See the older version of the reference documents here: http://doc.scalatest.org/2.2.6/#org.scalatest .FunSuite

If you are unable to update, the previous method for validating exceptions used the intercept method:

  test("Invoking head on an empty Set should produce NoSuchElementException") { intercept[NoSuchElementException] { Set.empty.head } } 
+13
source

All Articles