【问题标题】:How to make more readable and shorter a karate scenario如何使空手道场景更具可读性和更短
【发布时间】:2017-09-18 22:42:07
【问题描述】:

我是空手道框架的新手。我想写一个像这里这样的场景:

version 1 :
Background:
        * url 'someURL' 
        * def user1 = {id:'123', name:'Bill'}

Given I have a user with id '123'
When I create a new user with the same id
Then I should get a response 'user with this id already exists'

但在空手道中,我必须像这样写:

version 2 : 
Background:
    * url 'someURL' 
    * def user1 = {id:'123', name:'Bill'}

Given request user1
When method post
Then status 201
Given path response.id
When method get
Then response == {id:'123', name:'Bill'}

    * def idUser1 = response.id

Given request == {id: idUser1, name: 'Gary'}
When method post
Then response == {code: 400, message: 'user with this id already exists'}

如何获得空手道框架的第一个版本?我必须在哪里详细说明 3 行?前任: Given I have a user with id '123' 和后面(我不知道在哪里以及如何)用

详细说明
"Given request user1
When method post
Then status 201
Given path response.id
When method get"
Then response == {id:'123', name:'Bill'} etc.

【问题讨论】:

    标签: karate


    【解决方案1】:

    我是空手道的作者。如果您想要第一个版本,空手道不适合您。第一个版本没有用,除非您真的 真的希望您的产品所有者或业务分析师或非技术人员能够阅读(甚至创建)您的测试.根据我的经验,这种情况从不在实践中发生。

    即使您决定采用路径 1,您也需要编写大量 Java 代码作为 Cucumber“步骤定义”。这是浪费时间,您将失去空手道详细断言的好处,下面给出了示例:

    关于这个话题我还有很多话要说,但我的想法在这篇博文中详细解释了 - Yes, Karate is not true BDD

    无论您选择哪个选项,一切顺利:)

    【讨论】:

    • 我通过 JAVA API 运行了一个 UI 相关的功能,但我想知道如何使用这种方法从该功能运行单个场景?
    • 将可重复使用的场景移动到独立的功能文件中是否如此困难?我真的不明白你想做什么。
    • 这我知道我们可以为不同的场景创建独立的功能文件,但我想知道如何从单个功能文件中运行多个场景中的单个场景。我希望你现在明白了。
    • 那么这是问这个问题的错误地方:relishapp.com/cucumber/cucumber/docs/cli/run-specific-scenarios - 这甚至可能不适用于 Cucumber-JVM。万事如意,找到解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多