我是 python 的新手,目前正在学习如何使用 Lettuce (python) 编写 BDD 测试。我有一个非常简单的基于 Flask 框架的 REST API。我在调用 app.route 下的函数时有点卡住了。例如我的 API 看起来像这样
@app.route('/')
@app.route('/documentation')
def documentation():
return auto.html()
我的生菜测试在一个名为 features 的文件夹中。此文件夹 features 有两个文件,称为 test.feature 和 steps.py。test.feature 包含以下功能。
Feature: To test the root of API
Scenario: Call the root of the API
Given I have "/" or "/documentation"
When the user requests GET '/'
Then I response should be "GET HTTP/1.1 200".
定义写在 steps.py 文件中,如下所示。
@step('I have "([^"]*)" or "([^"]*)"')
def display_api(step, value, option):
print ('Attempting to display the API docs..')
-----
我不确定如何调用 @app.route('/') 来运行测试并将状态 200 返回给生菜,或者生菜将如何运行测试?我浏览了生菜文档,但仍然无法弄清楚如何对我的 REST API 进行自动化测试。任何建议或支持将不胜感激。在此先感谢您的时间。