軟件工程英文教學課件:Ch18 Testing Conventional Applications_第1頁
軟件工程英文教學課件:Ch18 Testing Conventional Applications_第2頁
軟件工程英文教學課件:Ch18 Testing Conventional Applications_第3頁
軟件工程英文教學課件:Ch18 Testing Conventional Applications_第4頁
軟件工程英文教學課件:Ch18 Testing Conventional Applications_第5頁
已閱讀5頁,還剩42頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、1Chapter 18Testing Conventional ApplicationsSoftware Engineering: A Practitioners Approach, 7/e by Roger S. Pressman2TestabilityOperabilityit operates cleanlyObservabilitythe results of each test case are readily observedControllabilitythe degree to which testing can be automated and optimizedDecomp

2、osabilitytesting can be targetedSimplicityreduce complex architecture and logic to simplify testsStabilityfew changes are requested during testingUnderstandabilityof the design3What is a “Good” Test?A good test has a high probability of finding an errorA good test is not redundant.A good test should

3、 be “best of breed”(所設計的測試用例同類最優(yōu)) A good test should be neither too simple nor too complex4Internal and External ViewsAny engineered product can be tested in one of two ways: Knowing the specified function that a product has been designed to perform, tests can be conducted that demonstrate each func

4、tion is fully operational while at the same time searching for errors in each function. (black-box method)Knowing the internal workings of a product, tests can be conducted to ensure that “all gears mesh(所有齒輪都相互嚙合)“, that is, internal operations are performed according to specifications and all inte

5、rnal components have been adequately exercised. (white-box method)5Test Case DesignOBJECTIVECRITERIACONSTRAINTto uncover errorsin a complete mannerwith a minimum of effort and time6Exhaustive Testing(窮舉法)There are 1014 possible paths! If we execute one test per millisecond, it would take 3170 years

6、to test this program!loop 20 X7Selective Testing(選擇法)loop 20 XSelected path8Software TestingMethodsStrategieswhite-boxmethods black-box methods9White-Box Testing. our goal is to ensure that all statements and conditions have been executed at least once .Basis Path Testing (路徑覆蓋測試)Logical Condition T

7、esting (邏輯覆蓋測試)10Basis Path Testing (路徑覆蓋測試)Step1:Draw the flow graph based on the design or the code of program(繪制程序圖).Step 2: Compute the cyclomatic complexity V(G) of the flow graph(計算程序圖的環(huán)域復雜度V(G).Step 3: Determine the basis sets of the independent paths (選擇能夠覆蓋所有邊的V(G)條獨立路徑).Step 4: Design test

8、 cases that will force execution of each independent path in the basis sets(設計強制執(zhí)行每條路徑的測試用例集). 2022/7/1811程序圖(flow graph):一種簡化的流程圖,用來考察測試路徑的工具。(1) 程序圖的基本控制結構: 結點:代表一條或多條順序執(zhí)行的語句,程序流程圖中的處理方框和菱形判定框可映射為結點。邊:代表控制流,類似于程序流程圖中的箭頭,(一條邊必須終止于一個結點,即使該結點并不代表任何語句)封閉區(qū)域:由邊和結點圈起來的范圍。Basis Path Testing- flow graph202

9、2/7/1812(2)程序圖的結構簡化:程序圖可將順序執(zhí)行的多個結點合并為1個結點;對流程圖中含有復合條件的判定框,先分解為幾個簡單條件判定框,再畫程序圖。程序圖關注的重點是判斷框,而不是執(zhí)行細節(jié)。(3)程序圖的用途:安排與驗證程序的路徑測試;考察與改進程序的結構復雜性。 Basis Path Testing - flow graph2022/7/1813例:畫出下面用PDL描述的程序段的程序圖IF a OR b THEN procedure x ELSE procedure yENDIFqBasis Path Testing - flow graph2022/7/1814分解復合判斷后的程序

10、圖如下:復合條件被分解為2個單獨的結點a和b。R1和R2是程序圖的2個封閉區(qū)域。qBasis Path Testing- flow graph15Basis Path Testing - cyclomatic complexity we compute the cyclomatic Complexity:1) number of simple decisions + 1 or2) number of enclosed areas + 1In this case, V(G) = 416Basis Path Testing- independent pathsWe derive the indep

11、endent paths:Since V(G) = 4,there are four paths:Path 1: 1,2,3,6,7,8Path 2: 1,2,3,5,7,8Path 3: 1,2,4,7,8Path 4: 1,2,4,7,2,4,.7,8Finally, we derive testcases to exercise these paths.1234567817Basis Path Testing Notesyou dont need a flow chart, but the picture will help when you trace program pathsbas

12、is path testing should be applied to critical modules2022/7/1818實例:冒泡排序程序,要求:畫出程序流程圖;將程序流程圖轉換為程序圖;計算環(huán)域復雜度;采用路徑測試法進行白盒測試,請設計測試用例,使其滿足路徑覆蓋。sort(int a ,int n) int i,j,temp; for (i=0;in;i+) for (j=0;jaj+1) temp=aj; aj=aj+1; aj+1=temp; 入口返回injaj+1Yi=i+1j=j+1Y2022/7/1819解:程序流程圖程序圖環(huán)域復雜度V(G)=判定結點數+1 =3+1 =4

13、V(G)=封閉區(qū)域+1 =3+1 =4入口返回injaj+1Yi=i+1j=j+1Y2022/7/1820解(續(xù))設計測試用例集使其滿足路徑覆蓋(即:點覆蓋+邊覆蓋) 1)A1=4,6,n=2 2)A2=6,4,2,n=3說明:測試集需覆蓋4條路徑P1:1,2,3,0P2:1,2,3,4,5,9,3,0P3:1,2,3,4,5,6,8,5,9,3,0P4:1,2,3,4,5,6,7,8,5,9,3,0A1覆蓋了P1,P2,P4A2覆蓋了P1,P2,P3入口返回injaj+1Yi=i+1j=j+1Y123465780921Logical Condition Testing(邏輯覆蓋測試)The

14、test case design method that exercises the logical conditions contained in a program module 邏輯覆蓋測試的5種標準(由弱到強)(1) 語句覆蓋:每條語句至少執(zhí)行1次;(2) 判定覆蓋:每一判定的每一分支至少執(zhí)行1次;(3) 條件覆蓋:每一判定中的每個條件,分別按“真”和“假”至少各執(zhí)行1次;(4) 判定/條件覆蓋:同時滿足判定覆蓋和條件覆蓋的要求;(5) 條件組合覆蓋:求出判定中所有條件的各種可能的組合值,每一可能的條件組合至少執(zhí)行1次。2022/7/1822利用流程圖中的判定框設計測試用例。PROCE

15、DURE EXAMPLE(A,B:REAL;VAR X:REAL) BEGIN IF (A1)AND(B=0) THEN X:=X/A; IF (A=2)OR(X1) THEN X:=X+1 END語句覆蓋測試數據如表所示,滿足語句覆蓋準測。入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YYNNABX期望204紅線邏輯覆蓋測試舉例2022/7/1823 判定覆蓋期望結果應該有具體的值,這里用有顏色的線表示。測試數據如下表所示,滿足判定覆蓋準測。語句覆蓋判定覆蓋稱完全覆蓋(路徑覆蓋)。ABX期望204紅線111藍線入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YY

16、NN判定1判定2判定2判定1FTFT邏輯覆蓋測試舉例2022/7/1824 條件覆蓋使每個條件都能取值為真和假。測試數據如右下表所示,滿足條件覆蓋準測。 ABX期望214紅線101藍線判定2判定1A1B=0A=2X1FFTFTFTT入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YYNN判定1判定2邏輯覆蓋測試舉例2022/7/1825 判定/條件覆蓋期望結果應該有具體的值,這里用有顏色的線表示。測試數據如右下表所示,滿足判定/條件覆蓋準測。 判定2判定1FTFTA1B=0A=2X1FFTFTFTT入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YYNN判定1判定2

17、ABX期望204紅線111藍線邏輯覆蓋測試舉例2022/7/1826條件組合覆蓋期望結果應該有具體的值,這里用有顏色的線表示。測試數據如右下表所示,滿足多重條件覆蓋準測。共8種組合條件:(1)A1,B=0(2)A1,B0(3)A1,B=0(4)A1,B0(5)A=2,X1(6)A=2,X1(7)A2,X1(8)A2,X1ABX期望204(1)(5)紅線211(2)(6)綠線102(3)(7)綠線111(4)(8)藍線入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YYNN注意:測試數據對黃色路徑并未測試到!如使第2行A=1可覆蓋該路徑。邏輯覆蓋測試舉例2022/7/1827邏輯覆

18、蓋標準的適應性分析語句覆蓋:查錯能力最弱,一般不單獨使用;判定覆蓋與條件覆蓋:一般情況,條件覆蓋優(yōu)于判斷覆蓋。但也可能出現:滿足條件覆蓋,但卻不滿足判斷覆蓋的情況。判定/條件覆蓋:彌補條件覆蓋的缺陷;條件組合覆蓋:在5種覆蓋中查錯能力最強,凡是滿足條件組合覆蓋的測試數據,必然滿足其余4種覆蓋。2022/7/1828例子:按邏輯覆蓋標準的要求設計冒泡程序的測試用例輸入:k(序列長度),Ak(無序數據)輸出:Ak(有序數據) FOR i:=2 TO k DO IF ai = ai-1 THEN FOR j:=i DOWNTO 2 DO IF aj = aj-1 THEN temp := aj; a

19、j := aj-1; aj-1 := temp; ENDIF ENDDO ENDIF ENDDO2022/7/18291) 語句覆蓋:每條語句至少執(zhí)行1次。測試用例:A=8,4,K=2,可滿足程序執(zhí)行時遍歷流程圖所有框的要求。潛在問題:若2個判定框中的“=”誤寫為“AI-1、AI=AI-1、AIAJ-1、AJ=AJ-1、AJAJ-1的情況至少出現一次。測試用例:A=8,4,9,6,K=4、A=8,4,8,4, K=4。 可合并為:A=8,4,8,4,9,6,K=64) 判定/條件覆蓋:同時滿足判定覆蓋和條件覆蓋的要求。 分析:該例中的2個復合判斷條件(=)并不獨立,即若為“真”,則必為“假”,

20、反之亦然。故考慮判定/條件覆蓋沒有實際意義。5)條件組合覆蓋:求出判定中所有條件的各種可能的組合值,每一可能的條件組合至少執(zhí)行1次。 分析:同上,考慮條件組合覆蓋沒有實際意義。例子:按邏輯覆蓋標準的要求設計冒泡程序的測試用例2022/7/1831組合條件測試的路徑選擇當程序中判定多于一個時,形成的分支結構可分為嵌套型分支結構和連鎖型分支結構。對于嵌套型分支結構,若有n個判定語句,需要n+1個測試用例;對于連鎖型分支結構, 若有n個判定語句,需要有2n個測試用例,覆蓋它的2n條路徑。2022/7/1832組合條件測試的路徑選擇33Loop TestingNested LoopsConcatena

21、ted (連鎖型)Loops Unstructured LoopsSimple loop34Loop Testing: Simple LoopsMinimum conditionsSimple Loops1. skip the loop entirely2. only one pass through the loop3. two passes through the loop4. m passes through the loop m n5. (n-1), n, and (n+1) passes through the loopwhere n is the maximum number of

22、 allowable passes35Loop Testing: Nested LoopsStart at the innermost loop. Set all outer loops to their minimum iteration parameter values.Test the min+1, typical, max-1 and max for the innermost loop, while holding the outer loops at their minimum values.Move out one loop and set it up as in step 2,

23、 holding all other loops at typical values. Continue this step until the outermost loop has been tested.If the loops are independent of one another then treat each as a simple loop else* treat as nested loopsendif* for example, the final loop counter value of loop 1 is used to initialize loop 2.Nest

24、ed LoopsConcatenated Loops36Black-Box Testingrequirementseventsinputoutput37Black-Box TestingHow is functional validity tested?How is system behavior and performance tested?What classes of input will make good test cases?Is the system particularly sensitive to certain input values?How are the bounda

25、ries of a data class isolated?What data rates and data volume can the system tolerate?What effect will specific combinations of data have on system operation?38Black-Box TestingBlack-box testing attempts to find errors in the following categories: incorrect or missing functionsinterface errorserrors

26、 in data structures or external database accessbehavior or performance errors39Equivalence Partitioning(等價類劃分)userqueriesmousepicksoutputformatspromptsFKinputdataEquivalence partitioning is a black-box testing method that divides the input domain of a program into classes of data from which test cas

27、es can be derived. An ideal test case uncovers a class of errorsEquivalence Partitioning等價類劃分 把全部輸入數據合理劃分為若干等價類,使每一等價類中的任何一個測試用例,都能代表該類中的其它測試用例。從而可用少量代表性測試數據,取得較好的測試效果。用例設計要點:在設計測試用例時,必須同時考慮有效等價類和無效等價類;每一無效等價類至少用一個測試用例,但允許若干有效等價類合用一個測試用例。4041Sample Equivalence Classesuser supplied commandsresponses

28、to system promptsfile namescomputational data physical parameters bounding values initiation valuesoutput data formattingresponses to error messagesgraphical data (e.g., mouse picks)data outside bounds of the program physically impossible dataproper value supplied in wrong placeValid dataInvalid dat

29、a42例:一個程序的功能描述如下,用等價類劃分法設計測試用例。功能描述:某城市的電話號碼由3部分組成。要求被測程序能接收一切符合下述規(guī)定的電話號碼,拒絕所有不符合規(guī)定的電話號碼。區(qū)號:空白或3位數字;前綴:非0或1開頭的4位數字;后綴:4位數字。輸入條件有效等價類無效等價類區(qū)碼空白(1);3位數字(2)有非數字字符(5);少于3位數字(6);多于3位數字(7) 前綴從2000到9999的3位數字(3)有非數字字符(8);少于4位數字(9);多于4位數字(10)起始位為0(11); 起始位為1(12)后綴4位數字(4)有非數字字符(13);少于4位數字(14);多于4位數字(15)測試用例測試范

30、圍期望結果 6510 2345等價類(1) (3) (4) 有效023 6511 1321等價類(2) (3) (4)有效20# 1234 4356等價類(5)無效剩下的10個用例無效等價類(6)-(15) 無效測試用例的設計:43Boundary Value Analysis(邊界值分析)userqueriesmousepicksoutputformatspromptsFKinputdataoutputdomaininput domainA greater number of errors occurs at the boundaries of the input domain rather than in the “center.” Boundary value analysis leads to a selection of test cases that exercise bounding val

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論