2010-01-22 5 views
1

다음 코드 실행에 대한 GWT 접근 방식을 사용하여 BDD를 연습하기 시작했으며 두 번째 테스트를 수행 할 수 없다는 것을 깨달았습니다.MSpec을 사용하여 GWT로 BDD하는 방법? 이 시나리오를 작성하는 올바른 방법

내 GWT는

Given there exists an open query 
When the user replies to the query 
Then it should save the reply if the reply is not blank 

같은 것이 그 다음은

그래서 나는 그렇게

public class when_user_replies_to_the_query : OpenQuery 
{ 
    Because 
    { 
     query.Reply(data); 
    } 

    ThenIt should_save_the_reply_to_the_database_if_there_is_a_reply 

    ThenIt should_notify_the_user_if_there_is_no_text_in_the_reply_and_not_save_to_database 
} 

public class Query 
{ 
    void Reply(string data) 
    { 
     //do something 
    } 
} 

그러나처럼 그것을 코딩이 비어있는 경우 응답을 저장할 사용자에게 통지하고 안 간다 첫 번째 경우에는 데이터에 무언가가 있어야하고 두 번째 경우에는 데이터가 빈 문자열이어야한다는 이유로 두 번째 사례를 수행 할 수 없다는 것을 깨달았습니다.

는이 경우 내가

Given the reply is blank 
When the user replies to the query 
Then it should notify the user ...... 

처럼 무언가로 내 GWT를 분할해야이 평균이, 그때는 반환 null의 경우 시나리오의 엄청난 금액을 작성하는 것합니까

values being null. Such as 
Given the database is null 
When retrieving queries 
Should reply with error message 
When saving queries 
Should save to file and reply with error message 
When // basically doing anything 
Should //give appropriate response 

내 BDD 사양을 작성하는 방법은 무엇입니까? 그리고 나는 심지어 올바른 포럼 O_O에 있습니까?

답변

2

두 개의 Then 절은 기본적으로 Query 클래스가 사용되는 다른 컨텍스트를 형성하기 때문에 반전하고 싶습니다. Then 상태를 모두 읽으면 "공백이 아닐 경우"및 "공백이면"두 컨텍스트 모두를 볼 수 있습니다.

  1. 상황에 맞는 # 1 :

    Given an open query 
    Given a non-blank reply 
    When the user replies to the query 
    It should save the reply 
    
    public class When_the_user_replies_to_the_query_and_the_reply_is_not_blank 
    { 
        static Query Query; 
    
        Establish context =() => 
        { 
         Query = new Query(); 
        }; 
    
        Because of =() => 
        { 
         Query.Reply("answer"); 
        }; 
    
        It should_save_the_reply =() => 
        { 
         // Use your imagination 
        }; 
    } 
    
  2. 상황 # 2 :

    Given an open query 
    Given a blank reply 
    When the user replies to the query 
    It should not save the reply 
    It should notify the user 
    
    public class When_the_user_replies_to_the_query_and_the_reply_is_blank 
    { 
        static Query Query; 
    
        Establish context =() => 
        { 
         Query = new Query(); 
        }; 
    
        Because of =() => 
        { 
         Query.Reply(String.Empty); 
        }; 
    
        It should_not_save_the_reply =() => 
        { 
         // Use your imagination 
        }; 
    
        It should_notify_the_user =() => 
        { 
         // Use your imagination 
        }; 
    } 
    

는 여러 가능한 "빈 응답"값 (null, String.Empty을 가질 수 있음을 고려하면, " ", \r\n), 컨텍스트 f 또는 이들 중 하나를 선택하십시오. 즉 응답은

  • 가 비어 응답
  • 하나의 컨텍스트가 비어 있지, 나는 종종 값의 상상할 수있는 조합에 대한 사양을 작성하지 않고,

    • 는 "행복한 경로"에 대한 하나의 컨텍스트가

      예를 들어, Query 클래스가 응답이 "is not empty"사양을 만족하는지 여부를 결정할 적절한 장소가 아니라고 주장 할 수 있습니다. 차라리 그 결정을 별도의 클래스로 작성해야하고 Query은 그 결정에 의존해야합니다.문제의

      • 분리 : 이것은 몇 가지 장점이 가져다 사용자 게시물 이전 응답에 문제가 있음을 암시의 Query 클래스 및 사양은 별도로
      • 가 여러 곳에서 사양을 다시 사용할 수 있습니다 진화 할 수 자신 빈 응답
      • 당신은 Query
      우려에 대해, 따라서 상황에 맞는 폭발을 방지 별도로 사용자 통지 및 저장 데이터베이스에 대한 걱정없이 시험 사양을 얻을 수 있습니다
    관련 문제