Creating our first simple test
Testing is one of the pillars of any software during development, and later during maintenance and expansion too. Especially in the case of web applications where the application will handle high traffic and be scrutinized by a large number of end users at all times, testing becomes pretty important, as the user feedback determines the fate of the application. In this recipe, we will see how to start with test writing and also see more complex tests in the recipes to follow.
Getting ready
We will start with the creation of a new test file named app_tests.py
at the root application level, that is, alongside the my_app
folder.
The unittest2
Python library also needs to be installed using the following command:
$ pip install unittest2
How to do it…
To start with, the contents of the app_tests.py
test file will be as follows:
import os from my_app import app, db import unittest2 as unittest import tempfile
The preceding code describes the imports needed for this test...