ScalaTest 106: Printing expected and actual values when a test fails

Problem: You’d like to have better output from your ScalaTest assert tests, output that shows the expected and actual values.


One approach is to use the === method instead of ==. When an assert test fails, the === method output shows the two values from the test.

ScalaTest 103: Writing a first BDD test with ScalaTest

Problem: You want to write your ScalaTest tests using a behavior-driven development (BDD) style.


Extend the ScalaTest FunSpec trait, typically with the BeforeAndAfter trait. Then use the approach shown in the following PizzaSpec test class.

A series of tests begins with the describe method, with individual tests declared in it methods:

ScalaTest 102: Writing TDD style unit tests with ScalaTest

Problem: You want to use test-driven development (TDD) style tests in your Scala applications, and need to see examples of how to write them.


Have your test classes extend the ScalaTest FunSuite, and then write your tests. Because most tests involve a setup and teardown process, you’ll usually also want to add in the BeforeAndAfter trait as well.