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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.