110 likes | 234 Views
Lesson 15: Testing. Software Engineering II. Lesson Objectives. Understand the importance of testing Learn how to maximize the effectiveness of unit testing using OO Understand why OO minimizes regression testing Understand why OO facilitates automated testing
E N D
Lesson 15:Testing Software Engineering II
Lesson Objectives • Understand the importance of testing • Learn how to maximize the effectiveness of unit testing using OO • Understand why OO minimizes regression testing • Understand why OO facilitates automated testing • Learn when to automate testing
IMPORTANCE OF PROPER TESTING • Validate the system for use • Defect free code a must for successful reuse • Users associate defects with quality
MAXIMIZING THE EFFECTIVENESS OF UNIT TESTING • Keep object interfaces to a minimum • High level of cohesion - object contains only functionally related components • Keep objects a reasonable size • Build large objects out of small objects • How to determine correct size: • McCabe’s Complexity Metric • Halstead’s Metrics • Rule of Thumb: Methods no more than two pages
1 3 4 5 6 7 8 9 1 0 1 1 2 MCCABE COMPLEXITY ANALYSIS AIDS UNIT SIZING • Graph shows potential execution paths • Complexity to be kept below a predetermined threshold • No unstructured code sequences FOR MORE INFORMATION: McCabe Associates Twin Knolls Professional Park 5501 Twin Knolls Rd. Suite 111 Columbia, MD 21045
HALSTEAD’S SOFTWARE SCIENCE - DEFINITIONS • Determine difficulty from the program • Calculate vocabulary of the program • Vocabulary = n1 + n2, where • n1=Number of unique operators • n2=Number of unique operands • Calculate length of the program • Length = N1 + N2, where • N1=Total operators • N2=Total operands • Calculate difficulty from vocabulary and length FOR MORE INFORMATION: Halstead, Maurice H. Elements of Software Science Elsevier North Holland, Inc. 1977
F4 F3 F1 S2 S1 F5 OO MINIMIZES REGRESSION TESTING • Regression testing retests capabilities after an update • Before OO, encapsulation was not enforced • This led to . . . Many units have access to the same data! Changing F2 could impact all other functions! F2a
OO MINIMIZES REGRESSION TESTING Encapsulation and Information Hiding prevent unintentional interactions Changing this object has little or no impact on other objects! O1a O3 O4 O5 O2
OO FACILITATES AUTOMATED TESTING • Automated test generation techniques work well for OO • Objects provide manageable units • Encapsulation provides natural test boundaries • Rigorous interfaces help generation of thorough test cases
WHEN TO AUTOMATE TESTING • Very large applications • Test more frequently during development • Narrow down changes to smaller sections of new code • Long life-cycle applications • Captures test cases when experts are still available • Frequently upgraded applications • Formal testing repeated many times
TESTING SUMMARY • OO maximizes the effectiveness of unit testing • Encapsulation minimizes impacts, reducing errors in regression testing • OO is well suited for automated testing • Automate testing for: • Very large applications • Long life-cycle applications • Frequently upgraded applications