2
我是cucumber
新。我已经为需要的罐子配置了cucumber
的环境。我想用cucumber
来测试其余的api。所以首先创建了.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();
}
}
我搜索了很多,但能不能找到从.java
文件发送GET
请求。
如何发送GET
请求cucumber
步骤定义和比较json
响应?
生成的步骤只是方法,所以你可以在它们中做任何其他的java方法。我认为[此链接](http://stackoverflow.com/questions/2793150/using-java-net-urlconnection-to-fire-and-handle-http-requests)将帮助您制作HTTP请求。 –