我是机器人框架自动化测试的新手,我使用Python为简单的Quiz应用程序编写了脚本和库,并遵循关键字驱动的测试用例方法。我的剧本是:
class Quiz(object):
OPTIONS = 'ab'
count = 0
def __init__(self):
self._score = 0
Quiz.count+=1
def score(self, str1):
if str1 not in self.OPTIONS:
raise QuizError("Invalid button '%s'." % str1)
if str1 == 'a' and Quiz.count == 1:
self._score +=1
elif str1 == 'a' and Quiz.count == 2:
self._score +=1
elif str1 == 'a' and Quiz.count == 3:
self._score +=1
return self._score
class QuizError(Exception):
pass图书馆档案:
from quiz import Quiz, QuizError
class QuizLibrary(object):
def __init__(self):
self._calc = Quiz()
self._result = 0
def option(self, answer):
self._result = self._calc.score(answer)
def result(self, expected):
if self._result != expected:
raise AssertionError('%s != %s' % (self._result, expected))keyword_driven.txt:
*** Settings ***
Library quizlibrary.py
*** Test Cases ***
Quiz Answer
option a
option b
option a
result 2它显示了以下错误:
Quiz Answer FAIL |
No keyword with name 'option' found.
----------------------------------------------------------------------------------------
Testcase :: Example test cases using the keyword-driven testing approach. | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed有人能帮我解决这个问题吗?
请让我知道如何创建关键字驱动的方法用户关键字。
发布于 2015-02-24 10:29:12
用于关键字库的Python模块的名称肯定有问题。
库QuizLibrary.py
类问答库(对象):
另外,不要忘记在" library“和这个库的名称之间至少有两个空格。
https://stackoverflow.com/questions/28689608
复制相似问题