What is a test management template?

I have a method that tests some assumptions and either follows the happy path or ends along the unhappy paths. I either designed it poorly, or I miss the flow control testing method.

if (this.officeInfo.OfficeClosed)
{
    this.phoneCall.InformCallerThatOfficeIsClosedAndHangUp();
    return;
}
if (!this.operators.GetAllOperators().Any())
{
    this.phoneCall.InformCallerThatNoOneIsAvailableAndSendToVoicemail();
    return;
}
Call call=null;
forach(var operator in this.operators.GetAllOperators())
{
    call = operator.Call();
    if(call!=null) {break;}
}

etc. I have introduced my dependencies. I have mokas. I can make sure that this or that is caused, but I don’t know how to check that a "return" is occurring. If TDD means that I am not writing a line until I have a test that fails without it, I am stuck.

How would you test it? Or is there a way to write it, which makes it more verifiable?

: , , , . , . . if, ? , Method_WithParameter_DoesntInvokeMethod8IfMethod7IsTrueandMethod6IsTrueAndMethod5IsTrueAndMethod4IsTrueAndMethod3IsFalseAndMethod2IsTrueAndMethod1isAaaaccck()?

+3
6

. - IHandleCall DoTheRightThing() 3 HandleOfficeIsClosed, HandleEveryoneIsBusy, HandleGiveFirstOperatorAvailable, . :

IHandleCall handleCall;
if (this.officeInfo.OfficeClosed)
{
    handleCall = new HandleOfficeIsClosed();
}
else if other condition
{
handleCall = new OtherImplementation();
}
handleCall.DoTheRightThing();
return;

, . , , if/else factory, , , , factory handleCall. DoTheRightThing() - (, , factory ).

, , :

var operator = this.operators.FindFirst();
call = operator.Call();   
+1

, : , this.officeInfo.OfficeClosed this.phoneCall.InformCallerThatOfficeIsClosedAndHangUp() , this.operators.GetAllOperators().

, , (phoneCall ..), , , - .

- (, "OfficeClosed true" ) : , , , .

+4

, . , , , "" . , phoneCall.InformCallerThatOfficeIsClosedAndHangUp, , - -. , unit test , ( , ..).

, . , NCover, , . , , , , .

+3

, . , , . , Add(int x, int y) 4 x = 2, y = 2, , 4, , Add .

, . , , . , GetPrime(int k) k th prime, , GetPrime(10) 29, . GetPrime Eratóstenes , , - . , , , , GetPrime(10) 29, .

+1

TDD, : , TDD , , , .

: 1) : SUT SUT 2) : ,

, , .

+1

The template described by Aaron Feng and K. Scott Allen would solve my problem, and this is in doubt. The only problem I see is that it requires all calculations to be done in front. The decision data object must be filled in front of all the conventions. This is great if it does not require consistent trips to permanent storage.

0
source

Source: https://habr.com/ru/post/1725235/


All Articles