3

我是新手cucumber。我已经为cucumber所需的 jar 配置了环境。我想用cucumber. 所以首先创建.feature文件并生成基本步骤定义。

.feature文件:

Feature: Test

  Scenario: List accounts
    Given the system knows about the following details:
      | name | value |
      | unit | 01    |
      | dept | 001   |
    When the client requests accounts
    Then the response code should be 200
    And the response should contain following details:
      | name    | value   |
      | unit    | 01      |
      | dept    | 001     |
      | acctype | current |

TestClass.java如下:

package testPackage;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.DataTable;
import cucumber.api.PendingException;
import cucumber.api.java.en.*;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        features={"classpath:cucumber.features/"},
        glue = {"testPackage"}      
        )

public class TestClass {

    @Given("^the system knows about the following details:$")
    public void the_system_knows_about_the_following_details(DataTable arg1) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        // For automatic transformation, change DataTable to one of
        // List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.
        // E,K,V must be a scalar (String, Integer, Date, enum etc)
        throw new PendingException();
    }

    @When("^the client requests accounts$")
    public void the_client_requests_accounts() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @Then("^the response code should be (\\d+)$")
    public void the_response_code_should_be(int arg1) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @Then("^the response should contain following details:$")
    public void the_response_should_contain_following_details(DataTable arg1) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        // For automatic transformation, change DataTable to one of
        // List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.
        // E,K,V must be a scalar (String, Integer, Date, enum etc)
        throw new PendingException();
    }

}

我搜索了很多,但找不到从文件发送GET请求。.java

如何从步骤定义发送GET请求并比较响应?cucumberjson

4

1 回答 1

0

如果你愿意使用 Spring,可以使用Spring 的 REST Template以 RESTful 方式发送 HTTP 请求。

Jackson还可以很好地解析预定义的 java 数据对象的响应/请求,这使得处理 JSON 的痛苦明显减轻。

于 2015-09-23T15:55:47.570 回答