Testing - Page P3-L15-1 MEF-TRANSITION-P3-L15-1 Dr. M.E. Fayad Lesson 15: Testing SoftwareEngineeringII
Testing - Page P3-L15-2 MEF-TRANSITION-P3-L15-2 Dr. M.E. Fayad Lesson Objectives oUnderstand the importance of testing oLearn how to maximize the effectiveness of unit testing using OO oUnderstand why OO minimizes regression testing oUnderstand why OO facilitates automated testing oLearn when to automate testing
Testing - Page P3-L15-3 MEF-TRANSITION-P3-L15-3 Dr. M.E. Fayad I MPORTANCE O F P ROPER T ESTING Validate the system for use Defect free code a must for successful reuse Users associate defects with quality
Testing - Page P3-L15-4 MEF-TRANSITION-P3-L15-4 Dr. M.E. Fayad M AXIMIZING T HE E FFECTIVENESS O F U NIT T ESTING 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
Testing - Page P3-L15-5 MEF-TRANSITION-P3-L15-5 Dr. M.E. Fayad M C C ABE C OMPLEXITY A NALYSIS A IDS U NIT S IZING 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 FOR MORE INFORMATION: McCabe Associates Twin Knolls Professional Park 5501 Twin Knolls Rd. Suite 111 Columbia, MD 21045
Testing - Page P3-L15-6 MEF-TRANSITION-P3-L15-6 Dr. M.E. Fayad H ALSTEAD’S S OFTWARE S CIENCE - D EFINITIONS 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 FOR MORE INFORMATION: Halstead, Maurice H. Elements of Software Science Elsevier North Holland, Inc. 1977
Testing - Page P3-L15-7 MEF-TRANSITION-P3-L15-7 Dr. M.E. Fayad OO M INIMIZES R EGRESSION T ESTING Regression testing retests capabilities after an update Before OO, encapsulation was not enforced This led to... F1 F5 F2a S1 S2 F4F3 Many units have access to the same data! Changing F2 could impact all other functions!
Testing - Page P3-L15-8 MEF-TRANSITION-P3-L15-8 Dr. M.E. Fayad OO M INIMIZES R EGRESSION T ESTING Encapsulation and Information Hiding prevent unintentional interactions O1a O2 O4 O5 O3 Changing this object has little or no impact on other objects!
Testing - Page P3-L15-9 MEF-TRANSITION-P3-L15-9 Dr. M.E. Fayad OO F ACILITATES A UTOMATED T ESTING 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
Testing - Page P3-L15-10 MEF-TRANSITION-P3-L15-10 Dr. M.E. Fayad W HEN T O A UTOMATE T ESTING 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 - Page P3-L15-11 MEF-TRANSITION-P3-L15-11 Dr. M.E. Fayad T ESTING S UMMARY 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