0

我有一个健身房的模拟个人资料页面,我要编写测试用例以用小黄瓜语言编辑该个人资料页面。我不喜欢小黄瓜测试用例格式。谁能帮我解决这个问题?

4

2 回答 2

0

在我看来,这个问题没有范围;但是,我会尝试回答。Gherkin 是一门没有技术障碍的语言;它强制整个团队基于创造性协作而不是技术细节来编写明确的基于需求的测试规范。Gherkin 的基本组件已在第一个答案中进行了解释。因此,我宁愿尝试按照问题中的要求给出一个工作示例,以清楚地理解 ,的Given使用。WhenThen

以下测试(称为测试规范)是用 Gherkin 在功能文件中编写的:

Feature: Google Book Searching from https://www.googleapis.com/books/v1/volumes?q={ID}

  Scenario Outline: Verify that the response status code is 200 and content type is JSON.
    Given webService endpoint is up
    When user sends a get request to webService endpoint using following details
      | ID | <ID> |
    Then verify <statusCode> and <contentType> from webService endpoint response
    Examples:
      | ID   | statusCode | contentType                       |
      | 1    | 200        | "application/json; charset=UTF-8" |
      | 9546 | 200        | "application/json; charset=UTF-8" |
      | 9    | 200        | "application/json; charset=UTF-8" |

现在这里是上述测试规范的步骤定义:

// for **Given** - as it has to ensure that the required webservice end-point is up:

   @Given("webService endpoint is up")
    public void webserviceEndpointIsUp() {
        requestSpecification = new RequestSpecBuilder().
                setBaseUri(prop.getProperty(BASE_URL)).
                build();
    }

// for **When** - as this is for the part when user sends the request to the webservice end-point and receives the response

@When("user sends a get request to webService endpoint using following details")
public void userSendsAGetRequestToWebServiceEndpointUsingID(Map<String, String> data) {
    String ID = data.get("ID");
    System.out.println("The current ID is: " + ID);
    String pathParameters = "?q" + "=" + ID;
    response = given().
            spec(requestSpecification).
            when().
            get(pathParameters);
}

// for **Then** - finally, here is the then part. When we're verifying the actual stuff mentioned in the Scenario

 @Then("verify {int} and {string} from webService endpoint response")
    public void verifyResponseStatusCodeAndContentTypeFromWebServiceEndpointResponse(int statusCode, String contentType) {
        Assert.assertEquals(statusCode, response.getStatusCode());
        Assert.assertEquals(contentType, response.getContentType());
    }

这只是 Gherkin 如何编写测试的一个示例,要编写这样的脚本还有很多东西需要学习。因此,我建议从以下链接开始:

  1. 写好小黄瓜

  2. Cucumeber-JVM 免费课程

于 2020-08-26T22:33:14.587 回答
0

编写小黄瓜测试没有硬性规定。但强烈建议您按照推荐的程序编写它们,以使其易于理解。gherkin 的主要目的是让团队以外的人了解整个测试过程。

编写小黄瓜必须满足三个主要条件。

使用预定义的语句开始您的测试,即Given ThenWhen. 您的功能文件应包含如下所示的步骤:

Given I land on homepage
When I click on the signup button
Then I see the error

还有其他关键字,例如:

And - Connect more than two steps

有关详细信息,请参阅此文档:

https://github.com/cucumber/cucumber/wiki/Given-When-Then

于 2017-03-13T11:45:46.863 回答