-Now that we saw this overview of white-box testing, I'd like - -2
-to start talking about specific coverage criterion. And I'm going to start - -3
-with the first one, which is Statement Coverage. This criterion is - -4
-going to be characterized by two aspects, the first one is which - -5
-are the Test requirements for the criteria and the second one - -6
-is how we measure Coverage for that criteria. In the case - -7
-of statement coverage, these test requirements are all the statements in - -8
-the program. So this is the basic, the first the, the simplest - -9
-coverage criteria in the white-box arena. Let me remind you the assumption - -10
-that we made at the beginning. White-box testing is based on the assumption - -11
-that if there isn't a faulty element in the code, we need - -12
-to exercise it. We need to execute it, in order to find the - -13
-fault. And that's exactly what statement coverage does. If there is a - -14
-statement that is faulty in the code, we need to exercise it, in - -15
-order to find the fault. And therefore, a good measure of how well - -16
-we exercise the code, is the ratio of the number of executed statements. - -17
-So all the statements that my test cases executed, to the total - -18
-number of statements in the program. The higher this number, the better - -19
-I exercise my code. And we can also look at coverage criterion - -20
-in terms of questions. So what is the questions they were trying - -21
-to answer when we look at a specific set of test cases - -22
-and we assess the statement coverage that they achieved. And the question - -23
-is whether each statement in the program has been executed. So, statement - -24
-coverage is satisfied when all the statements in the program have been executed. - -25
-And we can satisfy to different degrees and the degrees to which it's - -26
-satisfied is measured by this value. So now let's go ahead and measure - -27
-statement coverage on our printSum example. What I'm going to show down here is - -28
-this progress bar in which we show the amount of coverage, the percentage of - -29
-coverage achieved. So what this means is that the, if I get to - -30
-this point I've covered 25% of the statements in the code. And my goal - -31
-is to get up here to cover all the statements in the code. - -32
-We have two test cases for this code. The first one that we just - -33
-saw, consists of the inputs a equal to 3 and b equal - -34
-to 9, and the second one has the inputs a is equal to - -35
-minus 5 and b is equal to minus 8. So now let's see - -36
-what happens when we run this test case. When we run this test - -37
-case, I'm going to show you by highlighting in the code the parts that - -38
-we cover when we start executing the code. We cover the first statement, - -39
-then we always execute the second - -40
-statement, which computes the result, we continue - -41
-the execution, we get to the if statement. If the result is greater - -42
-than zero, in this case our result is 12 because we - -43
-are working with the inputs 3 and 9, and therefore we - -44
-execute the true part of the if, we execute the statement. - -45
-And at this point, we just jump to the end. Because we - -46
-do not execute the else part of the statement, since we - -47
-have executed a true one, and therefore, we cover this final - -48
-statement. So at the end of the execution of this test - -49
-case, we cover one, two, three, four, five statement out of seven - -50
-which is roughly speaking 71%. So we can mark in here - -51
-that we more or less got to 71% of coverage for - -52
-this code. Now let's look at what happens when we execute - -53
-test case number two. In this case again, we execute the - -54
-first statement, the second statement, the third statement. In this case - -55
-though, the first statement, when it evaluates the value of result, - -56
-it sees that the result is not greater than zero because - -57
-our inputs are minus five and minus eight. Therefore, you will execute - -58
-line number five. And because the result is less than - -59
-zero, you will also execute line number six. So, at - -60
-this point, all of the statements in our code are - -61
-executed and therefore, we achieved a 100% statement coverage, which - -62
-was our goal. Before looking at other kinds of coverage, - -63
-let's see how our statement coverage is used in practice. - -64
-First of all, statement coverage is the most used kind - -65
-of coverage criterion in industry. Normally for company that uses - -66
-statement coverage, the typical coverage target is 80-90%, which - -67
-mean the outcome of the test should be such - -68
-that 80-90% of the statements are exercised at the - -69
-end of testing. So at this point, you might - -70
-be wondering, why don't we just shoot for 100%? - -71
-Why don't we try to cover all of the - -72
-code? We just saw that we could do it. - -73
-And so I'm going to ask you the same question. -- cgit 1.4.1