chapter6softwaretesting内容摘要:
binarySearch() Example public int binarySearch(int sortedArray[ ], int searchValue) { int bottom = 0。 int top = 1。 int middle, locationOfsearchValue。 boolean found = flase。 locationOfsearchValue = 1。 /* the location of searchValue in the sortedArray */ /* location = 1 means that searchValue is not found */ while ( bottom = top amp。 amp。 !found) { middle = (top + bottom)/2。 if (searchValue == sortedArray[ middle ]) { found = true。 locationOfsearchValue = middle。 } else if (searchValue sortedArray[ middle ]) top = middle 1。 else bottom = middle + 1。 } // end while return locationOfsearchValue。 } 1 2 4 5 67 8 9 10 3 29 2020 by SEC The Control Flow Graph (CFG) of Function binarySearch() 1 2 3 4 5 6 7 8 9 10 30 2020 by SEC Cyclomatic Complexity圈複雜度 Cyclomatic plexity is a software metric(圈複雜度是一種軟體度量 ) – provides a quantitative measure of the global plexity of a program.提供了整個程式複雜度的一個量化衡量值 – When this metric is used in the context of the basis path testing the value of cyclomatic plexity defines the upper bound of independent the value of cyclomatic plexity defines an upper bound of number of tests (., independent paths) that must be designed and exercised to guarantee coverage of all program statements. 圈複雜度定義了測試 (獨立路徑 )個數的上限,而這些測試的設計與執行保證涵蓋所有程式碼。 31 2020 by SEC Cyclomatic Complexity (cont’d) Independent path – An independent path is any path of the program that introduce at least one new set of procedural statements or a new 路徑,其中至少引進一段新的程序性程式碼或一個新的條件 (也就是說,一個獨立路徑至少有一段路徑是前面找到的獨立路徑所沒有的 ) – In a flow graph, an independent path must move along at least one edge that has not been traversed before the path is defined .在 flow graph,一個獨立路徑至少需往一個 edge,而這個 edge在之前並沒有被包含 Examples: consider the CFG of binarySearch() – Path 1: 1210 – Path 2: 1234689210 – Path 3: 12346892310 – Path 4: 1234689234689210 (not an independent path) independent paths 32 2020 by SEC Cyclomatic Complexity (cont’d) Three ways to pute cyclomatic plexity: – The number of regions of the flow graph correspond to the cyclomatic plexity. 區域數與圈複雜度相等 – Cyclomatic plexity, V(G), for a flow graph G is defined as V(G) = E N + 2 where E is the number of flow graph edges and N is the number of flow graph nodes. E : 邊的個數 , N: 節點數 – Cyclomatic plexity, V(G) = P + 1 where P is the number of predicate nodes contained in the flow graph G. P是判斷 節 點的 個數 33 2020 by SEC Cyclomatic Complexity of Function binarySearch() 1 5 7 8 9 10 2 3 4 6 predicate nodes R1 R2 R3 R4 R5 regions 34 2020 by SEC Deriving Basis Test Cases 測試案例的獲得 The following steps can be applied to derive the basis set:步驟 1. Using the design or code as a foundation, draw the corresponding flow graph. 利用設計 (文件 )或程式碼畫出 flow graph 2. Determine the cyclomatic plexity of the flow 度 (由圈複雜度可知獨立路徑個數的上限 ) V(G) = number of regions = 5 V(G) = E N + 2 = 13 – 10 +2 = 5 V(G) = P + 1 = 4 + 1 = 5 35 2020 by SEC Deriving Basis Test Cases (cont’d) 3. Determine a basis set of linearly independent paths. 決定一組獨立路徑 (共 5條 ) Path 1: 1210 Path 2: 12310 Path 3: 1234592 … Path 4: 12346792… Path 5: 12346892… 4. Prepare test cases that force the execution of each path in the basis set. 對每個路徑準備可強制執行該路徑的測試案例 Path 1 test case: – Inputs: sortedArray = { }, searchValue = 2 – Expected results: locationOfSearchValue = 1 36 2020 by SEC Deriving Basis Test Cases (cont’d) Path 2 test case: cannot be tested standalone!找不到測試案例可直接單獨走完 path2 – Inputs: sortedArray = ?, searchValue = ? – Expected results: locationOfSearchValue = ? Path 3 test case: – Inputs: sortedArray = {2, 4, 6, 8, 10}, searchValue = 6 – Expected results: locationOfSearchValue = 2 Path 4 test case: – Inputs: sortedArray = {2, 4, 6, 8, 10}, searchValue = 4 – Expected results: locationOfSearchValue = 1 Path 5 test case: – Inputs: sortedArray = {2, 4, 6, 8, 10}, searchValue = 10 – Expected results: locationOfSearchValue = 4 37 2020 by SEC After Deriving Basis Test Cases 之後 Each test cases is executed and pared to its expected 案例都被執行,並跟預期的結果比較。 Once all test cases have been exercised, we can be sure that all statements are executed at least ,我們可確定全部的程式碼至少執行過一次 Note: some independent paths cannot be tested standalone because the test case required to traverse the paths cannot be 徑無法單獨測試,因為不能找到可走完這些路徑的測試案例 – In binarySearch(), the initial value of variable found is FALSE, hence path 2 can only be tested as part of path 3, 4, and 5 tests. 路徑 2只能由路徑 3, 4, 5分段走完 . (因為找不到測試案例可直接走完路徑 2) 38 2020 by SEC Graph Matricesw圖形矩陣 A graph matrix – A tabular representation of a flow flow graph – A square matrix with a size equal to the number of nodes on the flow graph. 方形矩陣大小與 flow graph的節點數量相同 – Matrix entries correspond to the edges between 值相當於一個邊 (edge) – Adding link weight to each edge to represent 在每個邊加入連結權重可以表示 the connection between nodes。 節點間的連線 the probability of the edge to be executed。 邊被執行的機率 the resource (., processing time or memory) required for traversing the edge. 走過邊需用到的資源 39 2020 by SEC Graph Matrices (cont’d) A connection matrix – A graph matrix with the link weight is 1 (representing a connection exists) or 0 (representing a connection does not exist) . graph matrix中權重 1表示有連線存在, 0表示連線不存在 – A row of the matrix with two or more entries represe。chapter6softwaretesting
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。