Chapter 9. Best Practice #7: Consider Testability
We write unit tests to validate parts of business logic, automate user interaction to maintain an error-free user experience, and avoid introducing bugs as the codebase evolves. In this section, we discuss the implications of using feature flags in combination with known practices of continuous integration.
When using feature flags in your application, you are creating a conditional alternative execution path. Imagine that you have a typical three-tier microservice composed of an API layer, a controller layer, and a Data Access Layer (DAL). Your engineering team set up a feature flag at the controller layer to gate the access to a new storage layer that won’t have any visible impact for the user.
In a typical CI/CD environment, a new code change is pushed to the source code repository, where it is compiled and all appropriate test cases are run (unit tests, integration tests, end-to-end tests, and so on). If successful, the new code will become part of the main branch.
There are two approaches here. On one end we have high-level testing, often called end-to-end testing or black-box testing. This approach tests the functionality from the outermost layer and ensures that the expected behavior is working without caring for how the underlying components operate. When using feature flags, high-level testing must assure that the application will produce the expected behavior when the feature is turned on.
On the other hand, when pursuing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access