Meet ScalaTest

Explore ScalaTest, the testing library used throughout the course.

What is ScalaTest?

ScalaTest is one of the most popular and complete testing frameworks in the Scala ecosystem. As we’ll see throughout this course, one of its key strengths is supporting many different testing styles. Before diving into writing our first tests, let’s introduce a few key definitions:

Main Concepts in ScalaTest

Concept

Meaning

Test

Any named snippet of code that can either succeed, fail, be pending, or be canceled.

Suite

A collection of tests. It’s the central unit of composition in ScalaTest, modeled in the Suite trait. Suite declares life cycle methods defining how to write and run tests.

Style traits

They extend the suite and override the life cycle methods to support different testing styles.

Mixin traits

They override the life cycle methods of the style traits to address particular use cases such as asynchronous testing and assertions on collections.

In ScalaTest we define test classes by composing style traits and mixin traits. Test suites are composed using Suite instances.

ScalaTest design

At the beginning of this course, we saw that tests play a fundamental role in confidently writing code of high quality. According to Bill Venners, the creator of ScalaTest, its main goal is to “improve the return on investment of testing.” Consequently, ScalaTest is not a framework ...