假设我有一个Python库来处理博客文章:
class BlogPost(object):
def __init__(self):
...
def create_a_blog_post(self):
...
def add_category(self, category):
...
def add_title(self, title):
...
我想要以下测试用例:
*** Test Cases ***
Create post with category
Create a blog post with category "myCategory"
Create post with title
Create a blog post with title "myTitle"
Create post with both
Create a blog post with category "myCategory" and title "myTitle"
我应该为只有类别、只有标题和两者创建单独的用户关键字吗?或者,是否有必要在关键字中添加任意数量的“修饰符”
此外,如果我们必须将一个关键字的结果传递给另一个关键字,如何创建这样的关键字:
*** Keywords ***
Create a blog post with category
Create a blog post
Add category <-- How do I pass the blog post I just created to "Add category"
我故意省略了示例中的参数处理,因为这不是重点:)
我会创建一个名为“创建博客帖子”的关键字,然后根据您的偏好传递关键字参数或键/值对
您的测试将如下所示:
与关键字参数相比,我更喜欢键/值对,因为它可以让您排列键和值,如“两者”示例中所示。如果您更喜欢关键字参数,它可能如下所示:
对于名称/值对,实现只需要在成对的参数上迭代,或者在关键字args上迭代
最简单的方法是将第一个关键字的结果保存在变量中,然后将该变量传递给下一个关键字
或者,一种稍微有点程序化的方法是
Create a blog post
返回一个带有添加类别的方法的对象,然后您可以使用Call Method调用该对象上的方法:相关问题 更多 >
编程相关推荐