Testing the route functions

Let's build our first test case. In this test case, we will be testing if the route functions successfully return a response when we access its URL. In a new directory named tests, at the root of the project directory, create a new file named test_urls.py, which will hold all of the unit tests for the routes. Each test case should have its own file, and each test case should focus on one area of the code that you are testing.

In test_urls.py, let's start creating what the built-in Python unittest library needs. The code will use the unittest library from Python in order to run all the tests that we create in the test case:

import unittest class TestURLs(unittest.TestCase): pass if __name__ == '__main__': unittest.main() ...

Get Mastering Flask Web Development - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.