Chapter 3. Clean Code Using ScalaTest

In this chapter, we will look at some examples of writing clean test code. You will also continue your learning of ScalaTest. We will explore the following:

  • Assertions
  • Matchers
  • Base test classes
  • Test fixtures

Note

Some of the text and examples in this chapter has been cited with the consent from official ScalaTest documentation at www.scalatest.org. This text and example is copyright of Artima, Inc.

Assertions

There are three default assertions that come out of the box with ScalaTest:

  • assert:

    We used this in Chapter 2, First Test-Driven Application. This is used for general assertions:

         test("one plus one") {      
             assert(1 + 1 == two)      
             assert(1 + 1 != three)    
          }
  • assertResult:

    This is used to differentiate between the expected ...

Get Scala Test-Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.