软件测试之“白盒测试”

【引言】工作关系,作为曾经的独立测试部门,现在与开发团队一起组成Scrum Team融合阶段。

因为以前的项目系统问题较多,上边大老板为了提高开发团队的代码提交质量,要求开发除了必要的Unit Test之外,也到做一些E2E的Functioanl Testing俗称Dev Testing;而QA的SIT Testing则可以侧重更广的E2E范围甚至直接上Regression。

而跟开发最近几次的会议讨论中,发现很多开发人员多次提出Dev Testing的侧重点和测试范围,并反复提到很可能与QA Testing有重复性工作。

作为从独立的QA/Testing部门来的测试人员,当开发把问题抛给我们的时候,我们可能比较套路的回复说,建议开发做“白盒测试”,而测试团队负责“黑盒测试”。

但其实从一直以来的“黑盒测试”入门软件测试的人来说,对什么是真正高效和有效的“白盒测试”并不十分清楚。所以需要补充下理论知识,并尝试了解下业内较为成熟的实践部分,再回头找开发团队讨论,并希望提供给他们一些关于“白盒测试”的好的思路。

参考

白盒测试:理论基础 ISTQB – White Box Testing Techniques in Software Testing 为什么国内很少有公司做白盒测试? Structure Based or White Box techniques

White-box test design techniques (also called structural or structure- based techniques) are used to derive test cases from an analysis of the program(code). Deriving test case after analysis or understanding programs is white box testing.

In contrast to black box testing where test cases are designed from specification.

How to derive test cases from a program? And also how to derive coverage metrics for tests undertake?

Test cases from code are similar to black box test cases, but think test data here – like what values you will provide to run through the code. The emphasis here is what lines will be executed with the data you provide. And  the minimum number of test cases to achieve this.

Blank Box testing limitations: During Black Box testing, depending on the tester’s experience, after a full round of System testing,  the lines of code covered varies between 30% and 70%. So that leaves a lot of lines of code untested.

Coverage metrics help understand  what lines are not covered and help us design test cases to increase the coverage. There are certain tools available to measure the lines of code covered when tests are run.

Statement coverage: If the test case executes every line of code in the program, it is called 100% statement coverage.

Decision coverage: If the test cases execute both the decisions, it is called 100% decision coverage.

Statement Coverage = Number of executable statements executed x 100                     Total number of executable statements Decision Coverage = Number of decisions exercised x 100                     Total number of decisions

Coding Structures: A program code can be sequential where statements execute one after another. Execution of code can also be based on a condition being true or false.

Sequential or Linear statements:  Example of a sequential code, where the program is executed line after line.

1  READ  A 2  READ B 3  Sum = A+ B

Test cases for Sequential statements are simple, assign values to A & B.

For eg, test case /data : A=1, B=2, will run through statements 1,2,3 or all the lines of this program. In this case, one test case is needed for 100% Statement coverage.

Selection or Decisions: In this case the computer has to decide if a condition is true or false. If it is true the computer takes one route, and if it is false the computer takes a different route.

IF (condition is true) Do this ELSE  (condition is False) Do something else END IF

Eg:

1 IF Age  > 16 2              Process License application 3 ELSE 4              Decline the License application process 5 END IF

Test cases: Age =18 tests lines 1,2,5 and Age =14 tests lines 1,3,4,5.

So, 2 test cases are needed to execute every line of code. And 2 test cases to execute the True and False conditions. So 2 test cases are needed for 100%  Statement and Decision coverage.

There may not always be an ELSE part, as below:

1 IF Age  >16 2    THEN 3     "Process License Application" 4  ENDIF

Test cases for the above, assigning Age =18 tests lines 1,2,3,4, so only one test case is needed to execute every line of code.

But 2  test cases are needed to test the decisions: 1 to execute the True (Age > 16)  and False(Age < 16). Why?

Because for  Age <16 , we need to ensure the program does not do anything, it needs to go to the ENDIF. 

Hence Decision coverage is stronger than Statement coverage. 100% Decision coverage ensures 100% Statement coverage. The vice versa is not true.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgdpxs.html