Testing Your Application
In the chapters so far, we bootstrapped our application using Activator, developed our web application using Scala and the Play framework, and added a Reactive microservice call using RxScala for data flow computations. Now we will go ahead and enter the unit test and controller testing using the BDD and Play framework.
In this chapter, we will cover the following topics:
- • Unit testing principles
- • Testing Scala applications with JUnit
- • Behavior-driven development principles
- • Testing with ScalaTest
- • Testing Play framework applications with ScalaTest
- • Running tests in Activator / SBT
The need for testingTest is a fundamental and very important part of software development. Without tests, we cannot be sure that our code works. We should perform tests on almost all the code we produce. There are things that don't make sense for testing, for instance, case classes and classes that just represent structural objects, or, in other words, classes without functions. If you have code that applies computations, transformations, and validations, you definitely want to test this code with a good code coverage, which refers to features or any important code that is not just structural.
Test coverage is important, because it allows us to do refactoring (improve application code quality by reducing code, creating generic code, or even deleting code) with trust. This is because, if you have tests and if you do something wrong by accident, your tests will let you know. This is all about having short cycles of feedback. The earlier the better; you want to know if you have introduced bugs as soon, and as close to development, as possible. Nobody likes to discover bugs that could be caught by a simple test in production.