Test Method-Equivalence Classification

Test Methods

The
classic definition of software testing method :
Software Testing (Software Testing), the operation of the program under the specified conditions to find program errors, measure software quality, and evaluate whether it can meet the design requirements. Process
standard definition:
software testing is The process of running or measuring a software system using manual or automated means, the purpose of which is to check whether it meets the specified requirements or to clarify the difference between the expected and actual results

The purpose of soft test:
find problems and check whether the system meets the needs. For
example, a common method for implementing the previous black and white gray box method is
Insert picture description here
as follows:

等价类划分法

边界值

因果图

判定表驱动法

正交实验法

功能图法

场景实验法

错误推断法

需求转化

设计文档

探索式测试

1. Black Box-Equivalent

(Use a small amount of data to represent a large amount of data to find the most representative value)
Because: the test is endless
(such as QQ registration, there are infinite combinations of mobile phone number password nicknames, because the test data is endless, then the test is endless)

Equivalent class division method:
Equivalent class: select a few representative data, this kind of data is equivalent to other values ​​of this class; 找出最小的子集,可以发现最多的错误;
◆ The method of dividing the equivalent class is to divide the input field of the program into several parts, and then from each part Select a few representative data as test cases
◆ The role of representative data of each category in the test is equivalent to other values ​​in this category, that is, if one example in a category finds an error , Other examples in this equivalence class can also find the same error.
◆ Conversely, if one example in a certain category does not find an error, other examples in this category will not detect the error.

** Two major features: ** Use cases that must be designed; cover most situations;

两类情况:
有效等价类:找出有效值的代表范围;
无效等价类:找出无效值的代表范围;

Equivalence classification principle

◆ If the input condition stipulates the range of values ​​or the number of values, one valid equivalence class and two invalid equivalence classes can be determined
◆ If one input condition indicates a "must be established" situation, then Divide a valid equivalence class and an invalid equivalence class
◆ If the input condition specifies a set of possible values ​​of the input data, and the program processes each value in a different way, then each value can be divided into a valid Equivalence class, and divide an invalid equivalence class (similar to the release of the subway at different times. It is also similar to standing in a good team in life such as watching a ball game)
◆ If we know that, each element in a certain equivalence class has been divided (Example) The processing method in the program is different, so the equivalence class should be further divided into smaller equivalence classes.
◆ After establishing the equivalence class, establish an equivalence class table and list all the divisions Equivalence class

Use case design based on equivalence classification

明确测试对象,Non-test objects are guaranteed to be correct
for each equivalence class 唯一的编号(so that these equivalence classes are set well)
设计一个新的测试用例,使其尽可能多地覆盖尚未覆盖的有效等价类. Repeat this step until all valid equivalence classes are covered by test cases.
设计一个新的测试用例,使其只覆盖一个无效等价类。Repeat this step so that all invalid equivalence classes are covered

(正常条件下取值范围放宽,在异常的无效的条件下要把取值范围缩小,让有效等价类都有用例应对,让每一个无效等价类都有唯一的用例应对)

Characteristics of equivalent classes

1. Test 相同的内容
2. If a test in the equivalence class can capture a defect, then select other tests in the equivalence class can also capture the defect
3. If a test in the equivalence class cannot capture the defect, then select the Other tests in the equivalence class will not capture defects (不是划分得越细化越好,最好是刚刚好)
4. If the equivalence class is correctly divided, the number of test cases can be greatly reduced, and the test will be accurate and effective
5. If 错误的将两个不同的等价类当作一个等价类, 那就会遗漏一种测试情况, on the contrary, if an equivalence class is regarded as two different Of equivalent classes, the test will be redundant.

Issues to be noted in the division of equivalence classes

Consider not only valid equivalence classes, but also invalid equivalence classes.
Carefully divide, review division is
too rough may miss software defects
Organization review

scenes to be used:
Input conditions (value range / number of values; required value set; Boolean value; a set of processing values; rules that must be observed; subdivide smaller equivalence classes;)

Example 1: Test a two-digit addition calculator

Test requirement:
Test whether the result of adding the two parameters is correct.
Among them: The input value between -99 and 99 is greater than 99 or less than -99. The input should be rejected, and an error message is displayed
Insert picture description here
for the first parameter. Enter the values ​​in the table with the second parameter, and the test results obtained are shown in the table:

Insert picture description here
Obviously, if I take 199 numbers from -99 to 99 for the first parameter and 199 numbers from -99 to 99 for the second parameter, it is impossible to add two digits Conduct an exhaustive test of all situations.
If exhaustive testing is not possible, we will face the following question:
After testing 1 + 1, 1 + 2, 1+ (-1) and 1+ (-2), is it necessary to test 1 + 3, 1+ 4?
If you do not perform an exhaustive test on the addition calculator program, can you safely believe that all parameter combinations are correct?
So you need to use the equivalent class division method

  • STEP1: According to the test requirements, it can be divided into three equivalent categories:

◆ One equivalence class of valid data and two equivalence classes of invalid data
◆ The equivalence class of valid data is: a collection of meaningful input data that is meaningful to the specification of the program
◆ The equivalence class of invalid data is : A collection of input data that is unreasonable or meaningless to the specification of the program
Insert picture description here

  • STEP2: Create an equivalence class table (similar to the basis of the test)
    ◆ In practical work, we usually establish an equivalence class table for all equivalence classes in the program after establishing the equivalence class, so that we can write test cases Based on time
    Insert picture description here
  • STEP3: Identify test cases

◆ Assign a unique number to each equivalence class in the equivalence class table
◆ Design a new test case so that it can 尽量覆盖尚未覆盖的有效等价类
repeat this step, so that all valid equivalence classes are covered by the test case
◆ and The previous step is similar. 设计一个新的测试用例,使它只覆盖一个无效等价类
◆ Repeat this step so that all invalid equivalence classes are covered by test cases
Insert picture description here

  • STEP4: refine the classification of equivalence classes

(If you find that the divided elements are handled differently in the program, you need to refine it again)
◆ When testing the equivalence interval of "-99 <= value <= 99"
◆ We will find that 10 + 40, -20+ 30 and -30 + (-30)
add positive numbers, add positive numbers and negative numbers, and add negative numbers are also different equivalence intervals (if binary, the two are different Yes, there are algorithm differences.)
Therefore, more equivalence classes can be divided, and now there are two valid and two invalid equivalence classes, and the added numbers are divided into positive and negative numbers:
Insert picture description here

Improve test cases:
Insert picture description hereIn fact, it can be more refined, such as input numbers, Chinese, and special characters, so invalid equivalence classes can be more refined.

According to the previous equivalent class method, we tested according to the test cases given in the test case table, and found no problems, then after the program goes online, if the following problems occur, why does the program prompt that the entered data is wrong?

Insert picture description here
Because only the scope is considered, and the boundary is not considered
. The boundary method in the next section will give a better solution.

Example 2: Withdrawal of Yu'ebao

Test demand:
Yu'ebao withdrawal to bank card adds new rules: fast arrival (2 hours) daily limit of 1w yuan and
more than 1w yuan can only choose ordinary arrival

Insert picture description here

Design use case:
Insert picture description here
Analyze the process again:
carefully analyze the demand, the daily limit is 1w, so it is necessary to distinguish between two scenarios (the first and nth withdrawals)
Insert picture description here

Example 3: Triangle test case design

Reprinted from:
https://blog.csdn.net/xuhongge/article/details/2632172
Take the triangle test as an example: enter 3 integers as the three sides of the triangle, and determine the type of triangle through the program.
In the triangle calculation, the three sides of the triangle are required: ABC.

      1、 当三边不可能构成三角形时提示错误,可构成三角形时计算三角形周长。
      2、若是等腰三角形打印“等腰三角形”, 若两个等腰的平方和等于第三边平方和,则打印“等腰直角三角形”。
      3、若是等边三角形,则打印:“等边三角形”。
      4、画出程序流程图并设计一个测试用例。

Analyze:

         1、构成三角形的条件:任意两边之和大于第三边;

         2、构成等腰三角形的条件:任意两边相等;

        3、构成等腰直角三角形的条件:任意两边相等,而且两条边的平方和等于第三边的平方和;

        4、构成等边三角形的条件:三条边都相等。

Insert picture description here
Test case:
Insert picture description here

Published 82 original articles · praised 7 · visits 4175

Guess you like

Origin blog.csdn.net/sunshine612/article/details/105279142