首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >柑桔框架与BBD黄瓜的集成

柑桔框架与BBD黄瓜的集成
EN

Stack Overflow用户
提问于 2016-04-14 05:32:36
回答 1查看 1.1K关注 0票数 0

我有一项任务把BBD和柑橘框架结合起来。BBD我们使用Cucumber并在特性文件中读取测试用例,如下所示

特点:人事管理

person_management.feature

代码语言:javascript
复制
Scenario: Check the informations from an person
    Given the person management system is initialized with the following data
      | id  |
      | 1   | 
    Then the name of Person will be Patrick.      

我们有PersonTest (使用Junit)

代码语言:javascript
复制
@RunWith(Cucumber.class)
public class PersonTest {

}

公共类PersonSteps { PersonManager管理器;

代码语言:javascript
复制
@Given("^the person management system is initialized with the following data$")
public void the_person_management_system_is_initialized_with_the_following_data(final List<Person> persons) throws Throwable {
    manager = new PersonManager(persons);
}

@Then("^Then the name of Person will be (\\d+)$")
public void the_name_of_person_will_be(final String name) throws Throwable {
    assertThat(manager.getCurrentPersonName(), equalTo(name));
}

}

PersonTest作为Junit测试运行的问题

我的Citrus使用了TestNG和,如下所示

代码语言:javascript
复制
@Test
public class PersonCitrusTest extends AbstractTestNGCitrusTest {

    /**
     * Test find company by id
     */
    @CitrusXmlTest(name = "findPersonTestCase")
    public void findPersonTestCase() {
    }

    }
}


<?xml version="1.0" encoding="UTF-8"?>
<spring:beans xmlns="http://www.citrusframework.org/schema/testcase"
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:http="http://www.citrusframework.org/schema/http/testcase"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                                  http://www.citrusframework.org/schema/testcase http://www.citrusframework.org/schema/testcase/citrus-testcase.xsd
                                  http://www.citrusframework.org/schema/http/testcase http://www.citrusframework.org/schema/http/testcase/citrus-http-testcase.xsd">
    <testcase name="findPersonTestCase">
        <description>Test Find Person</description>
        <variables>
            <variable name="personId" value="1"></variable>
        </variables>
        <actions>

            <!--
            1. Get Person
            2. Check the name of person
             -->

那么,我如何将两者结合起来呢?谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-04-21 09:16:46

我建议在Cucumber步骤定义中使用Citrus。就像这样:

代码语言:javascript
复制
public class PersonSteps {
    private Citrus citrus;
    private TestRunner runner;

    private PersonManager manager;

    @Before
    public void setUp(Scenario scenario) {
        citrus = Citrus.newInstance();
        runner = new DefaultTestRunner(citrus.getApplicationContext(), citrus.createTestContext());
    }

    @Given("^the person management system is initialized with the following data$")
    public void the_person_management_system_is_initialized_with_the_following_data(final List<Person> persons) throws Throwable {
         manager = new PersonManager(persons);

         runner.variable("personId", "1");
         runner.echo("TODO: Get person");
    }

    @Then("^Then the name of Person will be (\\d+)$")
    public void the_name_of_person_will_be(final String name) throws Throwable {
        assertThat(manager.getCurrentPersonName(), equalTo(name));

        runner.echo("TODO: Verify person");
    }
}

您必须在@ the注释方法中编写一些胶水代码,以便为Cucumber JUnit测试做准备。我不认为您可以在Citrus中对XML测试用例做同样的事情,所以您必须在这里使用Java。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36614562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档