from flask import jsonify
@app.route("/hello")
def hello():
return jsonify({'hello': 'world'})
Test:
import json
class MyTestCase(unittest.TestCase):
# ...
def test_hello(self):
response = self.app.get("/hello")
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['hello'], "world")
python - How to create a unit test to check the response of an API made in Flask? - Stack Overflow