2017-09-27 16 views
0

각 시나리오를 실행하기 전에 공통 단계를 실행하기 위해 배경 키워드를 사용할 수 있습니다. 마찬가지로 "After"키워드는 각 시나리오 다음에 커먼 (commons) 단계에서 사용할 수 있습니다. 자바 코드의 논리적 단계가 아니라 애프터 마개처럼 사용할 수 있습니다.After 키워드가 실행중인 오이 단계에 대해 배경처럼 사용할 수 있습니까

Background 
Given I use the API header information 
    | Content-Type | application/json;v=3 | 
And I connect to postgresql 

Scenario Outline: 
    And I get the "Request" payload from "5NB_CARD-A_Request" file for the scenario "CardA_Scenario1" 
    And I store the input payload individual field details for database validation 
    And I form a client with this resource url "/transaction" 
    When I make a POST call and capture the response 
    And I get the "response" payload from "5NB_CARD-A_Response" file for the scenario "CardA_Scenario1" 


Examples: 
| HTTPCode | 
| 200  | 

After 
Then I validate the output response with expected data 
And I verify the HTTP error code is "<HTTPCode>" 
And I fetch and validate latest created data from "transaction" table 
And I validate the created card is inserted into "field" table 

답변

0

짧은 답변 아래에, 당신은 아마이 here에, 만일 After 후크를 사용할 수 있습니다처럼 내가 필요하지만, 그것은 당신의 사건에 대한 시스템 권장 하지입니다. BDD는 비 기술적 인 이해 관계자와의 커뮤니케이션에 사용됩니다.

시나리오 개요를 작성한 방법은이 방법이 한 번만 실행되고 다른 경우 응답이 200 인 경우 마지막 2 단계는 실패합니다 첫 번째 Then).

확인해야 할 유일한 것은 응답이 200 인 행복한 흐름입니다. Scenario OutlineExamples 일 필요가 없습니다. 하나의 시나리오를 작성하기 만하면됩니다.

Background 
Given I use the API header information 
    | Content-Type | application/json;v=3 | 
And I connect to postgresql 

Scenario: Happy flow 
    And I get the "Request" payload from "5NB_CARD-A_Request" file for the scenario "CardA_Scenario1" 
    And I store the input payload individual field details for database validation 
    And I form a client with this resource url "/transaction" 
    When I make a POST call and capture the response 
    And I get the "response" payload from "5NB_CARD-A_Response" file for the scenario "CardA_Scenario1" 
    Then I validate the output response with expected data 
    And I verify the HTTP error code is "200" 
    And I fetch and validate latest created data from "transaction" table 
    And I validate the created card is inserted into "field" table 

응답 코드를 추가하려면 시나리오 개요를 다른 방법으로 다시 작성하는 것이 좋습니다. 확인을 위해 After 키워드가 필요하지 않습니다 (Then 걸음). 시나리오 요약을 사용할 때 어쨌든 한 번만 작성합니다.

Background 
Given I use the API header information 
    | Content-Type | application/json;v=3 | 
And I connect to postgresql 

Scenario Outline: 
    And I get the "Request" payload from "5NB_CARD-A_Request" file for the scenario "CardA_Scenario1" 
    And I store the input payload individual field details for database validation 
    And I form a client with this resource url "/transaction" 
    When I make a POST call and capture the response 
    And I get the "response" payload from "5NB_CARD-A_Response" file for the scenario "CardA_Scenario1" 
    Then I validate the output response with expected data 
    And I verify the HTTP error code is "<HTTPCode>" 
    And I fetch and validate latest created data from "transaction" table 
    And I validate the created card is inserted into "field" table 

Examples: 
| HTTPCode | 
| 200  | 

더 많은 응답 코드를 추가하는 경우 다르게 마지막 단계를 관리해야합니다 유의하십시오.

| Content-Type | application/json;v=3 |과 같은 세부 정보를 숨기고 단계 정의 내에서 관리하는 것도 좋은 방법 일 수 있습니다.

업데이트 :

나는 당신의 코멘트에서 수집 어떻게 당신이 그들을 사용하는 기능 파일 내에서 한 번만 작성하는 마지막 4 단계 (Then 단계) 모든 시나리오를 갖고 싶어한다는 것입니다.

제가 아는 한, Background과 동일한 확인 단계를 실행할 수있는 After은 Gherkin 언어의 전제 조건에 해당합니다.

간소화하는 방법이 있지만 재연 가능성이 줄어 듭니다. 예를 들어 정확히 동일한 네 개의 Then 단계를 사용하는 10 개의 시나리오와 2 개의 시나리오 개요가있는 경우보다 일반적인 단계로 모든 단계를 중첩 할 수 있으며 다른 단계 정의 파일에서 단계가 나온 경우 picocontainer을 사용할 수 있습니다 그것들을 그룹화하고 피쳐 파일 안에서 몇 번이나 호출 하는지를 줄이십시오. 더 자세한 내용 here.

문제는 Then 단계가 3 개의 매개 변수와 5 개의 인증을 갖고 있기 때문에 1 단계 또는 2 단계로 작성하는 것이 다소 복잡하다는 것입니다.

결론적으로 각 시나리오/시나리오 개요에 대해 작성하는 것이 좋습니다. 다른 사람이 해당 기능 파일을보고 어떤 파일이든 Then을 볼 수 없기 때문에 아래쪽에서만 찾을 수 있습니다. 더 좋은 방법은 시나리오 개요에서 더 많은 시나리오를 그룹화하여 시도하는 것이므로 단계가 그만큼 반복하지는 않습니다.

희망이 있습니다.

+0

감사합니다. 하지만 내가 요청한 주된 이유는 50 가지 이상의 시나리오가 있다는 것입니다. 모든 시나리오에 대해 단계는 다소 차이가 있지만 변경 가능한 단계는 내 질문에서 언급 한 중간 단계입니다. 각 시나리오마다 내 HTTP 코드가 바뀌고 '예 :'에 넣어서 유효성을 검사합니다. 다른 사람들을 위해 json과 실제 json의 내용으로 검증합니다. 그래서 나는 대부분의 단계를 반복해서 반복하는 것처럼 보입니다. 그래서 깨끗한 정의를 찾고있었습니다. 이 일을 도와 줄 수 있어요? – mmar

+0

죄송합니다. 귀하가하려는 일을 정확히 이해하지 못했습니다. 나는 답을 다시 한번 알려줄거야. –