我需要幫助!黃瓜春無法找到步定義
所以下面的代碼對我的作品(純的JUnit代碼)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration("classpath:/importMasterConfig.xml")
public class FeatureWrittenInJavaUsingSteps {
@Before()
public void setup(){
/*do something*/
}
@After
public void tearDown()
{
/*Do something*/
}
@Autowired
ItemServiceController service;
@Test
public void callingStepFunctionsExample(){
ItemServiceControllerTestsSteps steps = new ItemServiceControllerTestsSteps(service);
steps.I_prepare_a_X_item_for_the_X_dealer("only images and pricing", "furniture");
steps.I_perform_the_X_inventory_service_call("createItem");
steps.I_should_get_the_X_response_code("200");
steps.the_inventory_service_response_result_should_be_a_X_object("Vertical Item");
}
}
然而,當我嘗試使用黃瓜功能來運行這段代碼,它似乎無法正確生成。我假設我正在設置錯誤的項目。
這裏是我的步驟代碼:
@ContextConfiguration("classpath:cucumber.xml")
public class ItemServiceControllerTestsSteps {
//Common variables across steps - currently only local.
private VerticalItem itemToCreate;
private ServiceResponse response;
//Step specific variables.
@Autowired
private ItemServiceController itemService;
public ItemServiceControllerTestsSteps(ItemServiceController service){
itemService = service;
}
@Before()
public void setup(){/*Do something*/}
@After()
public void tearDown(){/*Do Something*/}
@Given("^I prepare a \"(.*)\" item for the \"(.*)\" dealer$")
public VerticalItem I_prepare_a_X_item_for_the_X_dealer(String itemType, String dealerType){ //Step function and factory in one.
/*Do stuff*/}
@When("^I perform the \"(.*)\" inventory service call$")
public void I_perform_the_X_inventory_service_call(String actionType){
/*Do Stuff*/}
@Then("^I should get the \"(.*)\" response code$")
public void I_should_get_the_X_response_code(String codeType){/*Do stuff*/}
@Then("^the inventory service response result should be a \"(.*)\" object$")
public void the_inventory_service_response_result_should_be_a_X_object(String expectedClassType){ /*Do Stuff*/}
}
這裏是我的cucumber.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="cucumber.runtime.java.spring stepDefinitions"/>
<context:annotation-config/>
<import resource="classpath:importMasterConfig.xml"/>
</beans>
最後這裏是我的亞軍類:
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "rerun:rerun.txt", "html:target/local-html-report/"},
glue = "stepDefinitions.ItemServiceControllerTestsSteps")
public class CucumberRunner {}
如果有人能請啓發我爲什麼JUnit亞軍工作和黃瓜之一不會我會成爲一個非常快樂的露營者!
@JasonI閱讀,你會得到構建錯誤在哪個行和什麼是構建錯誤消息? – erhun 2015-02-11 23:35:30
@erhun我在這方面取得了一些進展 - 我錯過了我的步驟定義頂部的@ContextConfiguration(「classpath:cucumber.xml」)代碼。但是,現在我的功能認爲步驟代碼沒有實現 – 2015-02-11 23:46:31
錯誤說「每一步」被忽略,並且「我可以實現提供的存根代碼的步驟」 – 2015-02-12 17:35:12