2012-08-22 3 views
1

jbehave 스토리를 순서대로 실행하려고합니다. 통합 테스트에 대한순차적으로 실행될 스토리 주문하기

내 패키지 구조, 나는 이야기가이 순서 a.story, b.story에서 실행하려는

src/it/some/package/name/packageA/a.story 
src/it/some/package/name/packageB/b.story 
src/it/some/package/name/c.story 

이하 나는에 GivenStories를 사용하여 시도

c.story 표시됩니다 jBehave하지만 작동하지 않는 것 같습니다 (올바르게 지정하지 않았을 수 있음). GivenStories 텍스트 작성을 가리킬 수 있고 jbehave가 통합 테스트를 실행할 때 내 컴퓨터 및 젠킨스에서 실행중인 스토리가 생성되는 것을 볼 수 있기 때문에 jbehave가 어떻게 순서를 작성하는지에 대한 통찰력을 보여 주면 매우 감사하겠습니다. 다른 실행 순서.

이 문제에 대한 도움을 주시면 감사하겠습니다. 감사!

답변

1

내가 사실은 내가 생각이 문제에 대한 주변의 일을 생각하면 SampleTesterSequence이 하나처럼 구성 될

먼저 내가이

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>${surefire.version}</version> 
    <configuration> 
    <includes> 
     <include>**/*TesterSequence.java</include> 
    </includes> 
    </configuration> 
</plugin> 

같은 받는다는 확실한 구성을 추가 GivenStories보다 훨씬 편리했다 당신은 스위트 룸이 이야기를 전 제품군에 언급 순서대로 A, B, C를 실행합니다 볼 수 있듯이

import org.junit.AfterClass; 
import org.junit.BeforeClass; 
import org.junit.runner.RunWith; 
import org.junit.runners.Suite; 



@RunWith(Suite.class) 
@Suite.SuiteClasses({ A.class,B.class, 
     C.class }) 
public class SampleTesterSequence { 
    @BeforeClass 
    public static void beforeStories() throws Exception { 
     //TODO Implement before story steps 
    } 

    @AfterClass 
    public static void afterStories() throws Exception { 
     //TODO Implement after story steps 
    } 
} 

아래에 표시, 때 surefire는 TesterSequence으로 끝나는 패턴을 찾는 테스트를 실행하고 해당 클래스를 먼저 실행하고 지정된 클래스에서 실행하려는 스토리를 실행합니다.

2

이 응답은 조금 늦은 것 같지만 어쨌든. 우리는 JB도 시도하고 있지만, 여전히 현실 세계에 대한이 작품을 만드는 데는 많은 문제가있는 것 같습니다.

우리는 모듈 내에서 작동하는 이야기를 들었지만, 모듈을 통해 호출하고 시도하면 (예 : 전화하려는 공통 스토리가있는 종속 항아리가있는 경우), 전혀 작동하지 않는 것 같습니다). 다음과 같이

불구하고 동일한 모듈에서

, 당신은 이야기의 오른쪽 자리에 GS 항목을 배치해야합니다 :

Story: Running BBB 

GivenStories: com/xxx/test/stories/test_aaa_user.story 

Given a BBB string 
When I set BBB to activate 
Then the BBB string is set to activate 

이는 BBB 하나 전에 AAA 이야기를 실행합니다.

0

JBehave가 테스트를 파일 시스템에서 찾은 순서대로 실행하기 때문에 이러한 상황이 발생합니다. 나는,이 경우

@Override 
public List<String> findClassNames(String searchIn, List<String> includes, List<String> excludes) { 

    String[] orderedTestListArray = retrtieveTestNamesFromBuildXml(); 

    List<String> scannedTestList = scan(searchIn, includes, excludes); 
    System.out.println("Scanned Test List: " + scannedTestList); 

    List<String> finalTestList = new ArrayList<String>(); 
    for(String x: orderedTestListArray) { 
     for(String y: scannedTestList) { 
      if(y.contains(x)) 
       finalTestList.add(y); 
     } 
    } 

    System.out.println("Final Ordered Test List: " + finalTestList); 
    return classNames(normalise(finalTestList)); 
} 

:이 문제를 방지하려면, 당신은 JBehave의의 StoryFinder 클래스를 확장하고 findClassNames을 무시할 수()는 (프로퍼티, 등의 build.xml 파일) 어딘가에 저장 한 정렬 된 목록을 사용하는 내가 실행할 명령 테스트의 목록이 포함되어 내 개미 build.xml 파일을 구문 분석하여 orderedTestListArray를 검색 :

private String[] retrtieveTestNamesFromBuildXml() { 
    String[] orderedTestListArray = null; 
    InputStream iStream = null; 
    try { 
     File file = new File("build.xml"); 

     if(file.exists()) { 
      iStream = new FileInputStream(file); 
      DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); 
      DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); 
      Document doc = docBuilder.parse(iStream);  
      NodeList propertyNodes = doc.getElementsByTagName("property"); 

      String orderedTestListString = null; 

      for (int i = 0; i < propertyNodes.getLength(); i++) { 
       Element elementNode = (Element) propertyNodes.item(i); 
       if(elementNode.getAttribute("name").equals("xed.tests.to.run")) { 
        orderedTestListString = elementNode.getAttribute("value"); 
        break; 
       }  
      } 

      orderedTestListArray = orderedTestListString.split(","); 
      for(int i = 0; i <= orderedTestListArray.length-1; i++) { 
       orderedTestListArray[i] = orderedTestListArray[i].trim(); 
       orderedTestListArray[i] = orderedTestListArray[i].substring(3, orderedTestListArray[i].length()); 
      } 
     } 
    } 
    catch (Exception e) { 
     System.out.println("Error parsing XML info from build.xml"); 
     e.printStackTrace(); 
     System.exit(1); 
    } 
    finally { 
     try 
     { 
      if(iStream != null) 
       iStream.close(); 
     } 
     catch (IOException e) 
     { 
      System.out.println("Error closing InputStream for build.xml"); 
      e.printStackTrace(); 
     } 
    } 
    return orderedTestListArray; 
} 

을 마지막으로, 다음과 같이 개미 또는 받는다는에서 실행하는 동안이 새로운 StoryFinder 클래스를 지정해야합니다

storyFinderClass=fullyQualifiedNameOfNewStoryFinderClass 
관련 문제