Create a testing class in the src/test/scala
directory, in a file named HelloWorldSpec.scala
. Put this inside the file:
import org.scalatest.{FlatSpec, Matchers}
class HelloWorldSpec extends FlatSpec with Matchers {
"Hello World" should "not be an empty String" in {
val helloWorld = "Hello World"
helloWorld should not be ("")
}
}
FlatSpec
and Matchers
, which are part of the ScalaTest library.FlatSpec
allows tests to be written in the Behavior-Driven Development (BDD) style. In this style, a sentence is used to describe the expected behavior of a given unit of code. The test confirms that the code adheres to that behavior. See the documentation for additional information.