Pairwise algorithm for software test case design

Pairwise algorithm

Pairwise was first proposed by L. L. Thurstone (29 may 1887 – 30 September 1955) in 1927. He is an American psychostatistician. Pairwise is also the product based on mathematical statistics and the optimization of the traditional orthogonal analysis method.

In the test process, test cases are organized for the case of multi parameter parameters and multi values, and all values of each parameter are combined with the values of other parameters, which is the orthogonal analysis method. The advantages are that the coverage of test cases is 100%, the disadvantages are that the number of test cases is huge, and the labor consumption of executing test cases is huge.

Pairwise algorithm comes from the product obtained by optimizing the traditional orthogonal analysis method. Its theory comes from mathematical statistics.

Core idea

1. In a group of test cases (each case is composed of the values of three parameters, such as [business type, certificate type, contact method]), each two elements are combined in pairs, and there are three combination methods (with location [business type, certificate type], [business type, contact method], [certificate type, contact method]);

2. The first group of tests consists of three combinations. The comparison principle with other group elements is that: [business type, certificate type] will only be compared with the first element of other groups, and [business type, contact information] will only be compared with the second element of other groups;

If [business type, certificate type], [business type, contact information] and [certificate type, contact information] appear in the elements in the same position of other valid groups respectively, this group of cases can be considered as redundant cases and deleted.

3. The final test case is the optimal test case set calculated by pairing algorithm

Write an example of this paragraph. If a test scenario has three fields to fill in: business type, certificate type and contact information, their optional values are shown in the figure. If it is fully covered, 333 = 27 use cases are required

The second point above is reflected in the figure:

The first two digits are 1 and a, only one is selected, and all the others are deleted
The last two digits are a and x. only the first one is deleted
The first two digits are 1 and b. only the first one is deleted
...
By analogy, there are only 9 combinations of pictures

Pairwise is based on the following 2 assumptions:

(1) Each dimension is orthogonal, that is, each dimension has no intersection with each other.

(2) According to mathematical statistical analysis, 73% of defects (35% for single factor and 38% for double factor) are caused by the interaction of single factor or two factors. 19% of defects are caused by the interaction of three factors.

Therefore, pairwise is generated based on the highest cost performance of the use case set generated by the interaction covering all 2 factors.

Another example:
The bank's counter account opening business involves more than ten input boxes, each of which has multiple options. If you want to fully cover all parameters, the number of use cases will be very large
Take five input box options as an example,

    ['activate a bank card','have an account','Open a passbook'],
    ['ID','certificate of officers','Household register','passport'],
    ['mobile phone','fixed telephone'],
    ['cash','transfer accounts','To be written off'],
    ['Personal current deposit','Follow your heart','Personal activity','Individual lump sum deposit and withdrawal'],

If the options of these five input boxes are completely combined, there are 34234 = 288 test cases

However, after filtering with Pariwise algorithm, only 19 cases need to be tested to cover most scenarios

Code demonstration
from allpairspy import AllPairs

parameters = [
    ['activate a bank card','have an account','Open a passbook'],
    ['ID','certificate of officers','Household register','passport'],
    ['mobile phone','fixed telephone'],
    ['cash','transfer accounts','To be written off'],
    ['Personal current deposit','Follow your heart','Personal activity','Individual lump sum deposit and withdrawal'],
]

print("PAIRWISE:")
for i, pairs in enumerate(AllPairs(parameters)):
    print("{:2d}: {}".format(i, pairs))
    ```
Input results
PAIRWISE:
 0: ['activate a bank card', 'ID', 'mobile phone', 'cash', 'Personal current deposit']
 1: ['have an account', 'certificate of officers', 'fixed telephone', 'transfer accounts', 'Personal current deposit']
 2: ['Open a passbook', 'Household register', 'fixed telephone', 'To be written off', 'Follow your heart']
 3: ['Open a passbook', 'passport', 'mobile phone', 'transfer accounts', 'Personal activity']
 4: ['have an account', 'passport', 'mobile phone', 'To be written off', 'Individual lump sum deposit and withdrawal']
 5: ['activate a bank card', 'Household register', 'fixed telephone', 'cash', 'Individual lump sum deposit and withdrawal']
 6: ['activate a bank card', 'certificate of officers', 'mobile phone', 'To be written off', 'Personal activity']
 7: ['have an account', 'ID', 'fixed telephone', 'transfer accounts', 'Personal activity']
 8: ['Open a passbook', 'ID', 'mobile phone', 'cash', 'Follow your heart']
 9: ['Open a passbook', 'certificate of officers', 'mobile phone', 'cash', 'Individual lump sum deposit and withdrawal']
10: ['have an account', 'Household register', 'mobile phone', 'transfer accounts', 'Follow your heart']
11: ['activate a bank card', 'passport', 'fixed telephone', 'transfer accounts', 'Follow your heart']
12: ['have an account', 'passport', 'mobile phone', 'cash', 'Personal activity']
13: ['Open a passbook', 'Household register', 'mobile phone', 'transfer accounts', 'Personal current deposit']
14: ['Open a passbook', 'ID', 'mobile phone', 'To be written off', 'Personal current deposit']
15: ['Open a passbook', 'ID', 'mobile phone', 'transfer accounts', 'Individual lump sum deposit and withdrawal']
16: ['Open a passbook', 'Household register', 'mobile phone', 'transfer accounts', 'Personal activity']
17: ['Open a passbook', 'passport', 'mobile phone', 'transfer accounts', 'Personal current deposit']
18: ['Open a passbook', 'certificate of officers', 'mobile phone', 'transfer accounts', 'Follow your heart']

The following is the supporting materials. For friends who do [software testing], it should be the most comprehensive and complete war preparation warehouse. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you!

Finally, it can be in the official account: programmer Hao! Get a 216 page interview document of Software Test Engineer for free. And the corresponding video learning tutorials for free!, It includes basic knowledge, Linux essentials, Shell, Internet program principles, Mysql database, special topics of packet capture tools, interface test tools, test advanced Python programming, Web automation test, APP automation test, interface automation test, advanced continuous integration of test, test architecture, development test framework, performance test, security test, etc.

If my blog is helpful to you and you like my blog content, please click "like", "comment" and "collect" for three times! Friends who like software testing can join our testing technology exchange group: 779450660 (there are various software testing resources and technical discussions)

Keywords: Algorithm software testing

Added by lukegw on Tue, 15 Feb 2022 10:28:27 +0200