2016-04-14 56 views
0

BBD'yi Citrus Frimework ile entegre etme görevim var. BBD biz Salatalık kullanmak ve buCitrus framework ve BBD Salatalık entegrasyonu

Özelliği gibi özellik dosyasında test vakası okuyun: Kişi Yönetimi

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.  

Biz PersonTest (kullanım JUnit)

var
@RunWith(Cucumber.class) 
public class PersonTest { 

} 

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 testi olarak

çalıştırmak Ve Narenciye Yani bu

@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 
      --> 

gibi TestNG ve xml testcase ile TestCase kullanmak sorun İkisini de nasıl entegre edebilirim? Teşekkürler

cevap

1

Salatalık adım tanımında Citrus Java DSL'yi kullanmanızı öneriyorum. Böyle bir şey:

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"); 
    } 
} 

Sen Salatalık JUnit testi için Citrus hazırlamak için @Before açıklamalı yöntemde bazı tutkal kodu yazmak zorunda. Aynı şeyi Citrus'taki XML testleriyle de yapabileceğinizi düşünmüyorum, bu yüzden Java DSL'i burada kullanmanız gerekiyor.

+0

Geri bildiriminizi almadan önce birçok yolu denedim ve bunun için dsl'yi de kullanıyorum. gibi: Citrus citrus = Citrus.newInstance(); TestDesigner testDesigner = new DefaultTestDesigner (citrus.getApplicationContext(), citrus.createTestContext()); testDesigner.send (HttpClient) .payload (""), http() metodu (HttpMethod.GET) .product_enum_data yolu (ur i)..; Ve sonra bu ReceiveHttpMessageBuilder durumu = testDesigner.receive (httpClient) .messageType (MessageType.JSON) .http() gibi yanıtı alırız; status.validateScript (jsonScript); ..... groovy betiğini kullanabilir ve bir bellek java nesnesinin değerini ayarlayabiliriz. –