The essence of my question is to try to understand and clarify for myself to achieve what goal are the descendants of the base class TestCase written (for example from TestCase from docs.python.org )? Similar to the TestCase-e class, also found in other libraries, for example: in jUnit, nUnit, etc.
For a more substantive discussion, let's take some example code in which there are several functionalities. Suppose there is a views.py module included in Blueprint auth . Recall that Blueprint is a term from the world of microfreamer Flask-a. In this example, several functionalities: changing the password, getting a token, adding and deleting a user.
Here is the code for this views.py module:
@auth.route('/users/register', methods=['POST']) @administrator_required def register_user(): pass @auth.route('/users/unregister', methods=['DELETE']) @administrator_required def unregister_user(): pass @auth.route('/users/change-password', methods=['PUT']) def change_password(): pass @auth.route('/users/token') @credentials_required def generate_token(): pass Again, this is just an example of a piece of code in which several functionalities. One could also give a mathematical class, where there are also several possibilities: addition modulo, entropy calculation, etc.
How to write unit tests to cover the checks of the code under test in which several functionalities. To pimera for this blueprint? What test suite should contain such a test class (a descendant from TestCase)?
- Maybe the test suite should cover the entire \ blueprint component?
- Perhaps you need a test suite that covers only one functionality. Thus, several test classes appear: TokenTest, RegisterUserTest, UnregisterUserTest, ChangePasswordTest?
- Or is it necessary to write a set of tests for a single method / function that is part of the implementation of the tested functionality?
UPD :
My question is not about "How to use Flask?" and not in “How to write a unit test for a Flask application?” I repeat once again, a piece from a Flask application is given only as an example, because it is difficult for me to argue abstractly and best of all with bringing any piece of code.