Creating Test Cases for Flask
After building the components of Flask, it is essential to create test cases to ensure their correctness and to fix their bugs. Among the types of testing, unit testing focuses on testing the effectiveness and performance of components independent of other modules or tasks. On the other hand, integration testing ensures the correctness of a Flask component’s functionality and reliability with all its dependencies together at runtime.
To implement these test cases, Python has a built-in module called unittest
that can provide a TestCase
superclass and the setUp()
and tearDown()
methods that build variations of test cases and test suites. There is also a third-party module called pytest
, which is simple, easy to use, and non-boilerplate and can provide reusable fixtures for setting up a test environment. In this chapter, we will highlight how to implement test cases using pytest
for some selected functionalities from our projects in Chapters 1...