Testing Features¶
Finatra provides the following testing features:
the ability to start a locally running server, issue requests, and assert responses.
the ability to easily replace class instances throughout the object graph.
the ability to retrieve instances in the object graph to perform assertions on them.
the ability to write powerful tests without deploying test code to production.
Types of Tests¶
What are we talking about when we talk about testing? At a high-level the philosophy of testing in Finatra revolves around the following definitions:
Feature Tests - the most powerful tests enabled by Finatra. These tests allow for verification of the feature requirements of the service by exercising its external interface. Finatra supports both black-box testing and white-box testing against a locally running version of a server. Classes can be selectively swapped out with dummy implementations or mocks inserted, and internal state asserted. See an example feature test here.
Note
It is worth noting that versions of these Feature Tests could be re-used for regression testing as part of larger system tests which could be run post-deploy for deploy verification and certification.
Integration Tests - similar to Feature Tests, but the entire service is not started. Instead, a list of modules are loaded with method calls and assertions are performed at the class-level. You can see an example integration test here.
Unit Tests - these are tests generally of a single class and since constructor injection is used throughout the framework, Finatra stays out of your way.
ScalaTest¶
The Finatra testing framework uses the Twitter recommended ScalaTest testing style FunSuite for framework testing and to facilitate the types of testing outlined above we have several testing traits to aid in creating simple and powerful tests.
For more information on ScalaTest, see the ScalaTest User Guide.
To make use of another ScalaTest testing style, such as FunSpec or others, see Test Mixins.
Resources on Writing Tests¶
Test Dependencies¶
Please be sure to read the section on including test-jar dependencies in your project.