2016-12-21 11 views
1

입력이 일부 어설 션을 변경하지만 거의 모든 것이 동일하게 유지되는 경우 어설 션 부분을 어떻게 다시 사용합니까? 예를 들어, 입력 중 하나가 마지막 어설트 만 변경하고 나머지는 그대로 유지됩니다.xBehave 테스트에서 어설 션 및/또는 설정을 다시 사용하는 방법은 무엇입니까?

"When CreateBidCommand is executed" 
     .x(() => 
     { 
      _createBidCommand = new CreateBidCommand(_client, _bidYear, _optionNumber, 
       _underwritingLicenseFiling, _underwriter, _bidType, _description, _claimsApplicationType); 
      _commandDispatcher.Send(_createBidCommand); 
     }); 
    "Then Bid should be created" 
     .x(() => 
     { 
      _bid = _bidRepository.FindByBidNumber(_client, _bidYear, _optionNumber); 
      Assert.NotNull(_bid); 
     }); 
    " with description" 
     .x(() => Assert.Equal(_bid.Description, _description)); 
    " with Client" 
     .x(() => Assert.Equal(_client.Id, _bid.Client.Id)); 
    " with OptionNumber" 
     .x(() => Assert.Equal(_bid.OptionNumber, _optionNumber)); 
    " with BidType" 
     .x(() => { Assert.Equal(_bid.BidType.Code, _bidType.Code); }); 
    " with ClaimsApplicationType " 
     .x(() => Assert.Equal(_bid.ClaimsApplicationType.Code, _claimsApplicationType.Code)); 
    " with RegulatoryBody" 
     .x(() => Assert.Equal(_bid.RegulatoryBody,_underwritingLicenseFiling.RegulatoryBody)); 
    " with Underwriter" 
     .x(() => Assert.Equal(_bid.Underwriter, _underwriter)); 
    " with UnderwritingFirm" 
     .x(() => Assert.Equal(_bid.UnderwritingFirm,_underwritingLicenseFiling.UnderwritingFirm)); 
    "Then one and only one BidProposal should be created" 
     .x(() => Assert.True(_bid.BidProposals().Count() == 1)); 
    " with BaseForm" 
     .x(() => Assert.Equal(_underwritingLicenseFiling.BaseForm, _bid.LatestProposal().BaseForm)); 
    "Then one and only one ClientPolicy should be created" 
     .x(() => 
     { 
      var clientPolicies = _clientPolicyRepository.FindByBidId(_bid.Id); 
      Assert.Equal(clientPolicies.Count(), 1); 
     }); 
    "Then ProductionSchedule should have only one step" 
     .x(() => Assert.True(_bid.LatestProposal().ProductionSchedule.Count() == 1)); 
    " and it should be Initial creation" 
     .x(() => 
       Assert.True(_bid.LatestProposal().ProductionSchedule.ElementAt(0).BidStatusType.Code == 
          BidStatusTypeCode.InitialCreation)); 

답변

0

서로 다른 필드는 이러한 정보를 의미 있고 읽기 쉬운 것으로 압축하는 것을 매우 어렵게 만듭니다. 생성 된 입찰가와의 비교에 사용할 수있는 무언가를 소개하십시오. 빌더 패턴을 사용하여 필요한 모든 필드를 사용하여 쉽게 작성할 수 있습니다. 예를 들어 : 빌더와

// (Type declared here just to make it obvious) 
FakeBid _expectedBid = new FakeBidBuilder().WithClient(_client) 
            .WithBidYear(_bidYear) 
            // etc. 
            .Build(); 

, 당신은 쉽게 그래서 예외적 또는 의미있는 데이터가 정말 눈에 띄게 여기에 설정 될 필요가 기본값을 설정할 수 있습니다.

_createBidCommand = new CreateBidCommand(
     _expectedBid.Client, 
     _expectedBid.BidYear, 
     // etc. 
     ); 

그리고 지금 당신이 FakeBid 클래스에 정규 표현을 넣어 :

AssertTrue(_expectedBid.Matches(_bid)); 

모든 뛰어난 검사 명령을 호출 할 때

, 당신은 지금이 가짜 입찰에서 매개 변수를 전달할 수 있습니다 별도로 확인할 수 있습니다.

입찰가 매칭이 작동하는 몇 가지 다른 방법에 대해 특별한 것이있는 경우 비즈니스 또는 담당자와 대화하여 입찰가와 그 의미에 대해 이야기하는 방법을 찾고 해당 언어를 캡처 할 수 있는지 확인하십시오. 다른 빌더와 클래스 이름.

입찰가 작성의 서로 다른 두 가지 측면이 서로 다른 두 가지 이해 관계자에게 가치가있는 경우 서로 다른 사례로 구분해야 할 수 있으므로 그 이유가 무엇인지 쉽게 파악할 수 있습니다.

클래스 수준의 예제/테스트가있는 주된 이유는 버그를 잡아 내거나 코드를 테스트하지 않기 때문입니다. 깨끗한 디자인을 시행하고 코드가하는 일과 가치있는 이유를 이해하고자하는 다른 모든 사람들에게 살아있는 문서를 제공하는 것입니다. 희망이 패턴은 당신에게 몇 가지 아이디어를 제공합니다.

0

나를 위해 표준 어설 션을 수행하는 테스트 DSL을 작성하면됩니다.

"When CreateBidCommand is executed" 
     .x(() => 
     { 
      _createBidCommand = new CreateBidCommand(_client, _bidYear, _optionNumber, 
       _underwritingLicenseFiling, _underwriter, _bidType, _description, _claimsApplicationType); 
      _commandDispatcher.Send(_createBidCommand); 
     }); 
    "Then Bid should be created" 
     .x(() => 
     { 
      _bid = _bidRepository.FindByBidNumber(_client, _bidYear, _optionNumber); 
      Assert.NotNull(_bid); 
     }); 
    "And the bid should have the properties descibed by the command" 
     .x(() => AssertBid(_bid, _description, _client, ...)); 
    ... 

여기에서 AssertBid은 내 테스트 DSL의 한 방법입니다.