2014-02-23 4 views
1

오이에서 테스트하고자하는 다음과 같은 기능이 있습니다. 그러나 입력 파일을 한 번만 처리하려고합니다 (@ 아래의 기능에서 제공). 그러나 매번 @Given 단계를 실행하는 것으로 보입니다. 이 기능을 다음 기능에서 한번만 실행할 수 있습니까?오이 피처 파일에서 @를 한 번만 실행하십시오

@fileValidation 

Scenario Outline: File Validation 

Given a file is uploaded with name "something.csv" 
Then response filename created should not match input filename "something.csv" 
And reason for errors should be "<Reason>" with error code "<Error code>" for row with RequestId "<RequestId>" 

Examples: 

    | RequestId  | Error code | Reason |  
    | 123   | 101  | Failure 1 | 
    | 124   | 102  | Failure 1; Failure 2 | 

행운이없는 단계를 제거하여 전후 후크를 시도해 보았습니다.

나는 또한 후크를 시도했지만 여전히 예제의 각 행에 대해이 루프를 사용하고 있습니다.

@fileValidation 
Scenario Outline: File Validation 

Background: Read the uploaded file "something.csv" 
Then response filename created should not match input filename "something.csv" 
And reason for errors should be "<Reason>" with error code "<Error code>" for row with RequestId "<RequestId>" 

Examples: 

    | RequestId  | Error code | Reason |  
    | 123   | 101  | Failure 1 | 
    | 124   | 102  | Failure 1; Failure 2 | 

답변

0

후크 작동합니다/근무해야합니다

@Before("@fileValidation") 
    public void file_is_uploaded() throws Throwable { 
     String fileName = "something.csv"; 
     processInputFile(fileName); 
    } 

    @After("@fileValidation") 
    public void clear() { 
     outputFileName = null; 
    } 

및 기능 파일

나는 이런 식으로 뭔가가있다. 또는 부울 플래그를 설정하고 검사 할 수 있습니다.

public class FileValidation { 
... 
... 
private boolean fileOpened = false; 

@Given("^a file is uploaded with name \"([^\"]*)\"$") 
public void a_file_is_uploaded_with_name(String arg1) throws Throwable { 
    if !(fileOpened) { 
    processInputFile(...); 
    fileOpened = true; 
    } 

} 
    ... 
} 
관련 문제