CS223: Software Engineering Lecture 21: Unit Testing Metric.

Slides:



Advertisements
Similar presentations
Software Testing Technique. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves.
Advertisements

Testing and Quality Assurance
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
David Woo (dxw07u).  What is “White Box Testing”  Data Processing and Calculation Correctness Tests  Correctness Tests:  Path Coverage  Line Coverage.
Figures – Chapter 24.
1 Static Testing: defect prevention SIM objectives Able to list various type of structured group examinations (manual checking) Able to statically.
1 Static Analysis Methods CSSE 376 Software Quality Assurance Rose-Hulman Institute of Technology March 20, 2007.
Detailed Design Kenneth M. Anderson Lecture 21
Software Metrics II Speaker: Jerry Gao Ph.D. San Jose State University URL: Sept., 2001.
Object-Oriented Metrics
1 Complexity metrics  measure certain aspects of the software (lines of code, # of if-statements, depth of nesting, …)  use these numbers as a criterion.
Chapter 9: Software Metrics
Comp 587 Parker Li Bobby Kolski. Automated testing tools assist software engineers to gauge the quality of software by automating the mechanical aspects.
1 Software Testing Techniques CIS 375 Bruce R. Maxim UM-Dearborn.
Cyclomatic Complexity Dan Fleck Fall 2009 Dan Fleck Fall 2009.
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
Lecture 17 Software Metrics
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
Design Space Exploration
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
CMSC 345 Fall 2000 Unit Testing. The testing process.
Prof. Mohamed Batouche Software Testing.
Software Architecture & Complexity By:- Pardesi Band Group
Software Testing The process of operating a system or component under specified conditions, observing and recording the results, and making an evaluation.
Software Measurement & Metrics
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 15b: Product Metrics for Software Software Engineering: A Practitioner’s Approach, 6/e Chapter.
Agenda Introduction Overview of White-box testing Basis path testing
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Lecture 23 Instructor Paulo Alencar.
Software Quality Metrics
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 19Slide 1 Chapter 19 Verification and Validation.
1 Metrics and lessons learned for OO projects Kan Ch 12 Steve Chenoweth, RHIT Above – New chapter, same Halstead. He also predicted various other project.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Creator: ACSession No: 7 Slide No: 1Reviewer: SS CSE300Advanced Software EngineeringSeptember 2005 Software Measurement – Estimation and Productivity CSE300.
CSc 461/561 Information Systems Engineering Lecture 5 – Software Metrics.
Measurement and quality assessment Framework for product metrics – Measure, measurement, and metrics – Formulation, collection, analysis, interpretation,
Chapter 1: Fundamental of Testing Systems Testing & Evaluation (MNN1063)
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
08120: Programming 2: SoftwareTesting and Debugging Dr Mike Brayshaw.
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
Metrics "A science is as mature as its measurement tools."
Dynamic Testing.
Cyclomatic complexity (or conditional complexity) is a software metric (measurement). Its gives the number of indepented paths through strongly connected.
CS223: Software Engineering Lecture 19: Unit Testing.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Testing Integral part of the software development process.
Software Test Metrics When you can measure what you are speaking about and express it in numbers, you know something about it; but when you cannot measure,
Software Testing.
Software Metrics 1.
Software Testing.
CS223: Software Engineering
Design Characteristics and Metrics
Software Engineering (CSI 321)
Object-Oriented Metrics
Types of Testing Visit to more Learning Resources.
Design Metrics Software Engineering Fall 2003
Design Metrics Software Engineering Fall 2003
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Halstead software science measures and other metrics for source code
Fundamental Test Process
IMPORTANT NOTICE TO STUDENTS:
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Software Metrics SAD ::: Fall 2015 Sabbir Muhammad Saleh.
Software Testing “If you can’t test it, you can’t design it”
Software Metrics using EiffelStudio
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Chapter 8: Design: Characteristics and Metrics
08120: Programming 2: SoftwareTesting and Debugging
Unit III – Chapter 3 Path Testing.
Presentation transcript:

CS223: Software Engineering Lecture 21: Unit Testing Metric

Recap Unit Testing Unit test patterns

Objective After completing this lecture the students will be able to Identify appropriate metric for unit testing of their project Follow unit testing best practices Write unit test cases and test results

Need for metrics To determine the quality and progress of testing. To calculate how much more time is required for the release To estimate the time needed to fix defects. To help in deciding the scope of the to be released product o The defect density across modules, o Their importance to customers and o Impact analysis of those defects

Verification Code has to be verified before it can be used by others Verification of code written by a programmer There are many different techniques o unit testing, inspection, and program checking Program checking can also be used at the system level

Code Inspections The inspection process can be applied to code with great effectiveness Inspections held when code has compiled and a few tests passed Usually static tools are also applied before inspections Inspection team focuses on finding defects and bugs in code Checklists are generally used to focus the attention on defects

Code Inspections… Some items in a checklist o Do all pointers point to something o Are all variables and pointers initialized o Are all array indexes within bounds o Will all loops always terminate o Any security flaws o Is input data being checked o Obvious inefficiencies

Code inspections… Are very effective and are widely used in industry (many require all critical code segments to be inspected) Is also expensive; for non critical code one person inspection may be used Code reading is self inspection o A structured approach where code is read inside-out o Is also very effective

Best practice

Static Analysis These are tools to analyze program sources and check for problems It cannot find all bugs and often cannot be sure of the bugs it finds as it is not executing the code So there is noise in their output Many different tools available that use different techniques They are effective in finding bugs like memory leak, dead code, dangling pointers,..

Formal Verification These approaches aim to prove the correctness of the program I.e. the program implements its specifications Require formal specifications for the program, as well as rules to interpret the program Was an active area of research Scalability issues became the bottleneck Used mostly in very critical situations, as an additional approach

Metrics for Size LOC or KLOC o Non-commented, non blank lines is a standard definition o Generally only new or modified lines are counted o Used heavily, though has shortcomings  Depends heavily on the language used  Depends on how lines are counted.

Metrics for Size… Halstead’s Volume o n1: no of distinct operators o n2: no of distinct operands o N1: total occurrences of operators o N2: Total occurrences of operands o Vocabulary, n = n1 + n2 o Length, N = N1 + N2 o Volume, V = N log 2 (n) The minimum number of bits necessary to represent the program.

Metrics for Complexity Cyclomatic Complexity is perhaps the most widely used measure Represents the program by its control flow graph with e edges, n nodes, and p parts Cyclomatic complexity is defined as V(G) = e-n+p This is same as the number of linearly independent cycles in the graph Number of decisions (conditionals) in the program plus one

Flow graph of a program

Connected component

Cyclomatic complexity example… 1.{ 2. i=1; 3. while (i<=n) { 4. J=1; 5. while(j <= i) { 6. If (A[i]<A[j]) 7. Swap(A[i], A[j]); 8. J=j+1;} 9. i = i+1;} 10.}

Example…

V(G) = = 4 Independent circuits 1.b c e b 2.b c d e b 3.a b f a 4.a g a No of decisions is 3 (while, while, if); complexity is 3+1 = 4

Complexity metrics… The basic use of these is to reduce the complexity of modules Cyclomatic complexity should be less than 10 Another use is to identify high complexity modules and then see if their logic can be simplified

Range of Cyclomatic Complexity ValueMeaning 1-10Structured and well written code High Testability Cost and Effort is less 10-20Complex Code Medium Testability Cost and effort is Medium 20-40Very complex Code Low Testability Cost and Effort are high >40Not at all testable Very high Cost and Effort

Tools NameLanguage supportDescription OCLintC, C++Static code analysis devMetricsC# Analyzing metrics Reflector.NETCode metrics GMetrics Java Find metrics in Java related applications NDepends JavaMetrics in Java applications

Advantages of Cyclomatic Complexity Helps developers and testers to determine independent path executions Developers can assure that all the paths have been tested at least once Helps us to focus more on the uncovered paths Improve code coverage Evaluate the risk associated with the application or program Using these metrics early in the cycle reduces more risk of the program

Other Metrics Halstead’s Measure Live Variables and span Maintainablity Index Depth of Inheritance (Depth in Inheritance Tree (DIT)) Number of Children (NOC)

Depth in Inheritance Tree (DIT) The DIT is the depth of inheritance of the class o i.e. number of ancestors in direct lineage in the object-oriented paradigm. DIT is a measure of how many ancestor classes can potentially affect this class. The deeper a class is in the hierarchy, o The greater the number of methods it is likely to inherit,  Makes it more complex to predict its behavior. Deeper trees constitute o Greater design complexity o Greater the potential reuse of inherited methods.

Example of DIT

Number Of Children (NOC) It is the number of immediate subclasses to a class in the class hierarchy How many subclass is going to inherit a method of the base class Greater the number of children o Greater the potential reuse o Greater the chance of improper abstraction of the base class o Greater the potential influence

NOC Example

Summary Goal of coding is to convert a design into easy to read code with few bugs Good programming practices like structured programming, information hiding, etc can help There are many methods to verify the code of a module – unit testing and inspections are most commonly used Size and complexity measures are defined and often used; common ones are LOC and cyclomatic complexity

Thank you Next Lecture: UI Design