White box series (four) condition decision coverage

Condition decision coverage

First, the definition:

Each program is determined at least once as a true value, we have a false value, such that each branch of the program at least once,
and so that each of the respective determination conditions to obtain a variety of possible values satisfies at least once.

Second, characteristics:

1, a combination of condition coverage and determining characteristics covering
2, meet with Example condition decision coverage must satisfy the statement coverage
3, meet with Example condition decision coverage must satisfy the condition cover
4, meet with Example condition decision coverage must satisfy decision coverage
5, with the proviso no consideration is determined covering each determination result (true or false) in combination, the path coverage is not satisfied

Third, the program flow:

Fourth, the source code:

demo.py

#encoding:utf-8
A = int(input('请输入A的值'))
B = int(input('请输入B的值'))
X = int(input('请输入X的值'))

if A > 1 and B == 0:
    X = X / A
if A == 2 or X > 1:
    X = X + 1
print('结束')

Fifth, test case design

Use Case No. Test Case Coverage Path Mulch expected results
1 A=2,B=0,X=4 ace (A>1), (B== 0), (A==2), (X>1) X = 3
2 A=1,B=1,X=1 a-b-d (A<=1), (B!=0), (A!=2), (X<1) X = 1

Execution Example 1, determination (A> 1 and B == 0 ) is true, execute X = X / A, X = 2;
determination (A == 2 or X> 1 ) is true, execute X = X + 1;
output X = 3;
end program

Example 2 execution determination (A> 1 and B == 0 ) is false, do not perform X = X / A;
determination (A == 2 or X> 1 ) is false, do not perform X = X + 1;
outputs X = 1;
end program

It can be derived from the above use cases:
1, the condition decision coverage statement coverage of test cases satisfies
2, the condition decision coverage of test coverage satisfies the condition, the determination cover
3, with the above-described embodiments are not considered true and false combinations each decision (path cover)

Sixth, by using the above-described embodiments achieve Python Unittest

# encoding:utf-8

import unittest


class TestDemo(unittest.TestCase):

    def demo(self, A, B, X):
        if A > 1 and B == 0:
            X = X / A
        if A == 2 or X > 1:
            X = X + 1
        return X

    def test_demo_with_conditional_and_decision_coverage_1(self):
        '''
        使用条件判定覆盖测试 方法demo
        A=2,B=0,X=4
        '''
        X = self.demo(A=2, B=0, X=4)
        expected = 3
        self.assertEqual(expected, X)

    def test_demo_with_conditional_and_decision_coverage_2(self):
        '''
        使用条件判定覆盖测试 方法demo
        A=-1,B=1,X=1
        '''
        X = self.demo(A=-1, B=1, X=1)
        expected = 1
        self.assertEqual(expected, X)

if __name__ == '__main__':
    unittest.main()




Guess you like

Origin www.cnblogs.com/snailrunning/p/11019436.html