我刚刚开始学习BDD,因为我想将我的Python Webdriver回归测试用例转换为使用BDD。我想获得BDD,因为它现在在业界广泛使用。
我正在关注一个包含功能和步骤文件的简单计算器教程。 当我从Python控制台运行功能文件时,我收到以下错误: 要从PyCharm运行它,请选择View - >工具Windows - >我选择了Python控制台。 打开Python控制台窗口然后输入PythonBDD / tests / features / calculator_feature.feature
>> PythonBDD/tests/features/calculator_feature.feature
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'PythonBDD' is not defined
>>> tests/features/calculator_feature.feature
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'tests' is not defined
>>> $ lettuce
File "<input>", line 1
$ lettuce
^
SyntaxError: invalid syntax
>>> $lettuce
File "<input>", line 1
$lettuce
^
SyntaxError: invalid syntax
>>> cd pythonbdd
File "<input>", line 1
cd pythonbdd
^
SyntaxError: invalid syntax
>>> calculator_feature.feature$ lettuce
File "<input>", line 1
calculator_feature.feature$ lettuce
^
SyntaxError: invalid syntax
>>> calculator_feature.feature lettuce
File "<input>", line 1
calculator_feature.feature lettuce
^
SyntaxError: invalid syntax
>>> calculator_feature.feature
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'calculator_feature' is not defined
>>> lettuce calculator_feature.feature
File "<input>", line 1
lettuce calculator_feature.feature
^
SyntaxError: invalid syntax
>>> PythonBDD/tests/features/calculator_feature.feature
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'PythonBDD' is not defined
如何运行功能文件?
我的代码树结构如下:
PythonBDD
-- app
--_init_.py
-- calculator.py
-- tests
-- features
-- calculator_feature.features
-- calculator_steps.py
calculator_steps.py
from lettuce import *
from nose.tools import assert_equals
from app.calculator import Calculator
@step(u'I am using the calculator')
def select_calc(step):
print ('Attempting to use calculator...')
world.calc = Calculator()
@step(u'I input "([^"]*)" add "([^"]*)"')
def given_i_input_group1_add_group1(step, x, y):
world.result = world.calc.add(int(x), int(y))
@step(u'I should see "([^"]+)"')
def result(step, expected_result):
actual_result = world.result
assert_equals(int(expected_result), actual_result)
calculator_feature.feature
Feature: As a writer for NetTuts
I wish to demonstrate
How easy writing Acceptance Tests
In Python really is.
Background:
Given I am using the calculator
Scenario: Calculate 2 plus 2 on our calculator
Given I input "2" add "2"
Then I should see "4"
答案 0 :(得分:0)
只需在测试目录中运行lettuce
。
还要注意树结构中calculator_feature.features
文件名中的拼写错误。
请注意PyCharm
Behave
和Lettuce
热门BDD框架都有built-in support。