如何集成Citrus框架和BBD Cucumber [英] How to integration Citrus framework and BBD Cucumber
问题描述
我的任务是将BBD与Citrus Frimework集成在一起.BBD我们使用Cucumber并像这样在功能文件中读取测试用例
I've a task intergrating the BBD with the Citrus Frimework. The BBD we use the Cucumber and read the test case in the feature file like this
功能:人员管理
person_management.feature
person_management.feature
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)
We have PersonTest (use Junit)
@RunWith(Cucumber.class)
public class PersonTest {
}
公共类PersonSteps {PersonManager经理;
public class PersonSteps { PersonManager manager;
@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测试运行的问题
The problem that the PersonTest run as Junit test
我的Citrus将测试用例与TestNG和xml测试用例一起使用像这样
And my Citrus use the testcase with TestNG and xml testcase Like this
@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
-->
那么我该如何整合它们呢?谢谢
So how could I integrate both of them? Thanks
推荐答案
我建议在Cucumber步骤定义中使用Citrus Java DSL.像这样:
I suggest to use the Citrus Java DSL inside the Cucumber step definition. Something like this:
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");
}
}
您必须在带注释的@Before方法中编写一些粘合代码,以便为Cicums准备Cucumber JUnit测试.我认为您无法在Citrus中对XML测试用例进行相同的操作,因此您必须在此处使用Java DSL.
You have to write some glue code in @Before annotated method in order to prepare Citrus for the Cucumber JUnit test. I don't think that you can do the same with XML test cases in Citrus so you have to use the Java DSL here.
这篇关于如何集成Citrus框架和BBD Cucumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!