Design method of test case (1)

Equivalence class division method:

 

1. Method introduction

 

1. Definition

 

It divides all possible input data, that is, the input domain of the program into several parts (subsets), and then selects a few representative data from each subset as test cases. This method is an important and commonly used black box test case design method. 2. Divide the equivalence class:
    

 

Equivalence class refers to a subset of an input field. In this sub-set, each input data is equivalent for exposing errors in the program, and it is reasonable to assume that: testing the representative value of a certain equivalence class is equivalent to testing other values ​​of this class, so all The input data is reasonably divided into several equivalence classes, and a small amount of representative test data can be used to obtain better test results by taking one data in each equivalence class as the input condition of the test. The equivalence class can be divided into two different situations: valid equivalence class and invalid equivalence class.

 

1) Effective equivalence class

 

Refers to the set of input data that is reasonable and meaningful for the specification of the program. The effective equivalence class can be used to verify whether the program achieves the functions and performance specified in the specification.

 

  2) Invalid equivalence class

 

Contrary to the definition of a valid equivalence class. Invalid equivalence class refers to a collection of input data that is unreasonable or meaningless to the specification of the program. For specific issues, there should be at least one invalid equivalence class, and there may be more than one.

 

When designing test cases, these two equivalence classes should be considered at the same time. Because the software must not only be able to receive reasonable data, but also be able to withstand unexpected tests, such tests can ensure the software has higher reliability.

 

3. Criteria for dividing equivalence classes:

 

1) Complete testing and avoid redundancy;
2) Dividing equivalence classes is important: the division of sets is divided into a set of disjoint subsets, and the subsets are the entire set;
3) and the entire set: Completeness;
4) Disjoint subsets: guarantee a form of non-redundancy;

5) Identify (select) a test case in the same class. In the same equivalence class, the processing is often the same, and the same processing is mapped to the "same execution path".

 

4. The method of dividing equivalence classes

 

1) When the input condition specifies the value range or the number of values, one valid equivalence class and two invalid equivalence classes can be established. For example: the input value is the student's score, and the range is 0-100;

 

 

image

 

 

2) In the case that the input condition specifies the set of input values ​​or the condition of "what must be", a valid equivalence class and an invalid equivalence class can be established;

 

3) When the input condition is a Boolean quantity, a valid equivalence class and an invalid equivalence class can be determined.

 

4) When a set of values ​​(assuming n) of input data is specified, and the program needs to process each input value separately, n valid equivalence classes and one invalid equivalence class can be established.

 

Example: The input conditions indicate that the degree can be one of the four types: junior college, undergraduate, master, and doctoral degree. Then take these four values ​​as the four effective equivalence classes, and take any degree other than the four degrees as Invalid equivalence class.

 

 5) In the case of stipulating the rules that the input data must comply with, one valid equivalence class (conforming to the rules) and several invalid equivalence classes (violating the rules from different angles) can be established;

 

6) When it is known that each element in the equivalence class has been divided into different ways in program processing, the equivalence class should be further divided into smaller equivalence classes.
  
5. Design test cases

 

After the equivalence class is established, the equivalence class table can be established to list all the equivalence class input conditions: valid equivalence class, invalid equivalence class, and then the following three equivalence classes are divided Principle design test case:

 

1) Specify a unique number for each equivalence class;

 

2) Design a new test case to cover as much as possible the effective equivalence classes that have not been covered, and repeat this step until all the effective equivalence classes are covered;

 

3) Design a new test case to cover only an invalid equivalence class that has not been covered, and repeat this step until all invalid equivalence classes are covered.
  
2. Actual combat exercises

 

1. A program stipulates: "Enter three integers a, b, and c respectively as the side lengths of the three sides to form a triangle. The type of triangle formed is determined by the program, when the triangle is a general triangle, an isosceles triangle or an equilateral triangle When, calculate separately... ". Use equivalence class division method to design test cases for this program. (The complexity of the triangle problem is that the relationship between input and output is more complicated.)

 

 Analyze the requirements for input conditions given and implied in the question: 

 

  (1) Integer (2) Three numbers (3) Non-zero number (4) Positive number   
  (5) The sum of both sides is greater than the third side (6) Isosceles (7) Equilateral 

 

   If a, b, and c meet the conditions (1) ~ (4), one of the following four cases will be output:

 

   1) If the condition (5) is not met, the program output is "non-triangular".

 

   2) If the three sides are equal, the condition (7) is satisfied, and the program output is "Equilateral triangle".

 

   3) If only two sides are equal, that is, condition (6) is satisfied, the program output is "isosceles triangle".

 

   4) If the three sides are not equal, the program output is "general triangle". 

 

 List and number the equivalent class table

 

image

 

Test cases for covering effective equivalence classes: abc covering equivalence class numbers 3 4 5 (1)--(7) 4 4 5 (1)--(7), (8) 4 5 5 (1)--( 7), (9) 5 4 5 (1)--(7), (10) 4 4 4 (1)--(7), (11) Test cases covering invalid equivalence classes:

 

image

Software testing exchange group: 785128166

WeChat public account: Programmer Erhei; After paying attention, you can receive a set of video resources for free; explain in detail: python automated testing, web automation, interface automation, mobile terminal automation, interview experience and other related content, the value of learning resources depends on you Action, don’t be a "collector"

Here is a collection of selected dry goods articles for functional testing:

Dry goods sharing | Featured article collection of functional tests (Are you afraid that you can't find the article you need?)

Guess you like

Origin blog.csdn.net/m0_52668874/article/details/115219515