Let's consider an example of the development of the division function
As a rule, everyone wants to do their job faster and what happens.
The producer writes the specification:
Function
Result=DivisionFunction(divisor, divisible)
Mathematical formula:
6/3=2
The programmer specifies:
1. what type of data do you want to return an integer or not?
2. What will be the dimension?
The producer says
1. integer
2. dimension 4 bytes
The programmer writes the function:
Function Divide(iA,iB:integer):integer; begin result:=iA div iB; end;
Checks work
Preedure Test_Divide; var iRes: integer; begin iRes:=Divide(6,3); // check resilt if iRes<>2 then TestFrameWork.ShowError('Error 6/3<>2') else TestFrameWork.ShowOk('passed 6/3=2');
As a rule, this is all over, the work is done, the functionality works correctly.
Tester:
1. Study specifications
2. Planning test cases
а) What happens if instead of an integer enter a fractional number?
б) If we divide by 0, what happens?
в) How should a function with negative values work?
In the specification it is not written, respectively, it is not clear what the result should be, refers to the producer for clarification.
The Director finishes the specification:
The input parameters are only positive, if the divisor is zero then handle the exception, if the parameters are incorrect or the exception is returned 0.
The task leaves the programmer to implement.
The programmer changes the function:
Function Divide(iA,iB:cardinal):cardinal; begin if iB = 0 then result:=0 else result:=iA div iB; end;
Checks work
Preedure Test_Divide; var iRes: integer; begin iRes:=Divide(6,3); // check resilt if iRes<>2 then TestFrameWork.ShowError('Error 6/3<>2') else TestFrameWork.ShowOk('passed 6/3=2'); iRes:=Divide(6,0); // check resilt if iRes<>0 then TestFrameWork.ShowError('Error 6/0=0') else TestFrameWork.ShowOk('passed 6/0=0');
Then creates a program Test_Divide.exe in which the tester can enter their values and see the result.
Next, the tester checks the work in this program
Tester does the test
0/0=0 - error code
0/1=0 - it's not a mistake
1/0=0 - this is a mistake
That is clearly not the correct error handling logic.
Code using the Divide function will not work correctly! He will consider a mistake, what it not is.
Zero should not be an error code.
Sends the producer a test case.
The producer agrees and changes the specification.
“return minus 1 in case of erroneous parameters or exception.”
The programmer rewrites the code
Function Divide(iA,iB:cardinal):integer; begin if iB = 0 then result:=-1 else result:=iA div iB; end;
Checks work
Preedure Test_Divide; var iRes: integer; begin iRes:=Divide(6,3); // check resilt if iRes<>2 then TestFrameWork.ShowError('Error 6/3<>2') else TestFrameWork.ShowOk('passed 6/3=2'); iRes:=Divide(6,0); // check resilt if iRes<>-1 then TestFrameWork.ShowError('Error 6/0=-1') else TestFrameWork.ShowOk('passed 6/0=-1'); iRes:=Divide(0,1); // check resilt if iRes<>0 then TestFrameWork.ShowError('Error 0/1=0') else TestFrameWork.ShowOk('passed 0/1=0');
On this very small and primitive function, you can see how much the specification and tests can change at the time of testing and how important it is to start testing as soon as possible and write test cases at the stage of writing specifications.