O'Reilly logo

Learning Scala Programming by Vikash Sharma

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing in style using ScalaTest

We've tested the HelloSpec class, so we'll take a look at the test, and the way it's written. So, we can open the file Hello located in src/test/scala/example. The source code looks as follows:

package example 
 
import org.scalatest._ 
 
 
class HelloSpec extends FlatSpec with Matchers { 
  "The Hello object" should "say hello" in { 
    Hello.greeting shouldEqual "hello" 
  } 
} 

Taking a look at the code sample, we can observe a few points:

  • We've imported org.scalatest._ to bring all the traits we want to use.
  • The class definition named HelloSpec extends FlatSpec along with the mix-in Matchers class. It's a convention to name our test specifications as class name followed by Spec.
  • The definition consists of only one specification. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required