我有一个健身房的模拟化资料页面,我要编写用于用Gherkin语言编辑该配置文件的测试用例。我不是小黄瓜测试用例格式。有人可以帮我吗?
编写小黄瓜测试没有艰难而快速的规则。但是,强烈建议您通过遵循建议的程序来编写它们,以使其可以理解。小黄瓜的主要目的是给您团队以外的人,了解整个测试过程。
有三个主要条件,您必须满足写小黄瓜的书面。
使用预定义的语句即Given
Then
和When
开始测试。您的功能文件应该具有看起来像这样的步骤:
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-then
在我看来,这个问题没有范围;但是,我会尝试回答。小黄瓜是一种没有技术障碍的语言。它强制执行整个团队根据创意协作而不是技术细节编写基于需求的测试规格。第一个答案已经解释了小黄瓜的基本成分。因此,我宁愿尝试按照问题的要求给出一个工作示例,以了解Given
,When
,Then
的使用。
以下测试(称为测试规范)写在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());
}
这只是一个例子,即测试是如何用小黄瓜编写的,还有很多要学会能够编写此类脚本的例子。因此,我建议从以下链接开始:
写好黄瓜
cucumeber-jvm免费课程