Chapter 7Testing

Learning to write tests is one of the foundations that leads to a reliable and maintainable code base. With frameworks like ScalaTest, Spec2 and other mature frameworks, this chapter examines some of the most popular ways to create tests that can provide value to the longevity of your code.

Let's quickly review the common terminology for the categories of tests that are covered:

  • Unit Tests: Single pieces of code that you want to test, which are usually best for identifying failures in functions and algorithms.
  • Integration Tests: Shows the major system components working together properly. There are no mock objects, and everything is real as it would be in the live system.
  • Acceptance Tests: Basically these are “your feature stories,” asking yourself if you built the right thing based on the business requirements.
  • Property Tests: Tests the behavior of a function using generated inputs to “stress test” the validity of a piece of code.
  • Test-Driven Development (TDD): writing tests ahead of the feature (that's it!), which is handy when you want to describe the actions of a feature before you start implementing. You then rely on refactoring to create a suite of tests at a low level of regression.
  • BDD (Business-Driven Development): writing tests in a more natural semantic way. Really it's ...

Get Professional Scala now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.