Adding Human-Readable Information
Learn how to print debug information in the test case and generate coverage reports.
Log messages
We’ve met many different ScalaTest tools so far, allowing us to assert a wide range of properties using two testing styles (assertions and matchers). However, we haven’t focused on log messages. Log messages are also very important for testing code, although not as important in applicative code. Our tests do complex operations and assert many properties, so logging information can be useful. Also, we can display information to clarify what’s being done during the test.
We can do that in three ways. The most obvious is using println
statements. It works but fits poorly in the test output, as we’ll see shortly. ScalaTest offers two better ways: Informers
and GivenWhenThen
. In this lesson, we’ll explore these three ways.
The println
statements
The most basic way of printing information during the execution of our tests is by using println
statements. The following example retrofits the EducativeSpec
class, adding println
statements.
Get hands-on with 1400+ tech skills courses.