Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC309 Lecture 12

CSC309 Lecture 12

Software Engineering II
Test Coverage
(202405)

Javier Gonzalez-Sanchez

February 07, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs CSC 309 Software Engineering II Lecture 12: Test Coverage

    Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227
  2. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    3 Note Sprint 2 Presentation This Friday!
  3. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    4 Peer-Evaluation Stories – Task Blueprint Code – Test Cases Presentation Perception of Contribution to their Team Overall Evaluation
  4. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    5 Demo of your project. Show your project running. Particularly New Features Intelligent Tutoring System JFreeChart, JDBC, JSON, Maps API, Weather API, OpenAI API First Act – Demo
  5. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    6 Taiga à Stories, Backlogs, and Task board Stories (INVEST), Sprint backlog, product backlog. Estimation (story points) Talk about tasks; who is doing what? Everybody is doing some programming! Show and explain your Burndown Chart. Second Act – Your process
  6. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    7 Each Team Member Should be Able To Describe Story 1 Story 2 Story 3 Task A Task B Task B Task A Task A Task B
  7. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    9 Show your class diagram. Use colors for the newly added classes) If there are new functionalities, then there are new classes, right? (Single Responsibility Principle) What are the A, I, or D in the new class? (show the 2D plot regarding where your classes are in terms of the pain zone) Third Act – Software Design
  8. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    11 Show US your GitHub Who is doing What? (everyone is adding or updating code) Show US your Code and Code Metrics Are your metrics OK (LOC, eLOC, lLOC, CC)? Any significant aspect that you want to share? Do you acquire technical debt for something? What did you that made this code better than the one in the CSC 308 submission? Test Cases (Unit Testing) What are you testing? Why? Fourth Act – Code
  9. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    12 § Sprint Retrospective § Sprint Review Fifth Act – Code
  10. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    14 Key Ideas CSC 309 idea requirements architecture design code unit testing quality measure
  11. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    15 § Unit testing is the testing of an individual unit or group of related units. § It test that a unit is producing expected output against given input. § Each Unit developer must define Unit Test Cases for that Unit. § Unit Testing Frameworks are tools and libraries that help to implement the Unit Testing process. Example JUnit Unit Testing
  12. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    16 § Statement Coverage: each statement is executed at least 1 time. § Decision (branch) Coverage: each decision point is executed at least 1 time for true and one time for false. § Decision-Condition Coverage: each branch or decision point is evaluated to be both true and false, and each condition within a complex decision point is evaluated to be both true and false Coverage
  13. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    19 1. public void exampleMethod (int a, int b) { 2. if (a > 10 && b < 5) { 3. System.out.println("Branch 1"); 4. } else { 5. System.out.println("Branch 2"); 6. } 7. } // Achieving Statement Coverage: 2 test cases Test Case 1: a = 11, b = 4 (True branch, a > 10 is true, b < 5 is true) Test Case 4: a = 9, b = 6 (False branch, a > 10 is false, b < 5 is false) // Achieving Decision (Branch) coverage: 2 test cases Test Case 1: a = 11, b = 4 (True branch, a > 10 is true, b < 5 is true) Test Case 4: a = 9, b = 6 (False branch, a > 10 is false, b < 5 is false) Example
  14. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    20 1. public void exampleMethod (int a, int b) { 2. if (a > 10 && b < 5) { 3. System.out.println("Branch 1"); 4. } else { 5. System.out.println("Branch 2"); 6. } 7. } // Achieving Decision-Condition Coverage: 4 test cases Test Case 1: a = 11, b = 4 (True branch, a > 10 is true, b < 5 is true) Test Case 2: a = 9, b = 4 (False branch, a > 10 is false, b < 5 is true) Test Case 3: a = 11, b = 6 (False branch, a > 10 is true, b < 5 is false) Test Case 4: a = 9, b = 6 (False branch, a > 10 is false, b < 5 is false) Example
  15. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    21 1. if (x<1 || y>5 && z!=0 || flag==true && s==null) 2. doThis(); 3. else 4. doThat(); § How many Test cases are needed to Test for 100% statement coverage? § How many Test cases are needed to Test for 100% decision coverage? § How many Test cases are needed to Test for 100% decision-condition coverage? Decision-Condition Coverage
  16. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    23 Lab Calculate coverage for the following scenarios
  17. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    24 1.x = 0; 2.if (x < 10) 3. doSomething(); 4.x =5; Statement coverage? Decision coverage? Decision-Condition coverage? 1. Test Yourselves
  18. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    25 1. if (a <10 || b>5) 2. x = 50 3. else 4. x = 0; 5. if (w == 5 || y>0) 6. z = 48; 7. else 8. z = 5; Statement Coverage, Decision Coverage, and Decision-Condition Coverage with a = 0, b=0, w=0, y=0? Statement Coverage, Decision Coverage, and Decision-Condition Coverage (adding) with a=10, b=4, w=5, y = anything? Note: Remember that coverage is cumulative 2. Test Yourselves
  19. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    26 1. start =0; 2. end = 0; 3. found = false; 4. while (starts <= end and ! found ) { 5. middle =(start - end)/2; 6. if (key > table[middle]) { 7. start = middle +1 8. } else if (key == table[middle]) { 9. found = T 10. LOC = middle; 11. } else 12. end = middle -1; 13. } 14. } Statement Coverage, Decision Coverage, and Decision-Condition Coverage with: //TestCase1 table={10, 20, 30, 40, 50, 60, 70}, key=55 //TestCase2 table={10, 20, 30, 40, 50, 60, 70}, key=40 3. Test Yourselves
  20. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    27 If they are not already, how many test cases are needed for 100% Statement Coverage 100% Decision (Branch) Coverage 100% Decision-Condition Coverage For each of the 3 cases (code) shown before? 4. Test Yourselves
  21. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    28 3,4. Test Yourselves (solution) 1. start =0; 2. end = 0; 3. found = false; 4. while (start <= end && ! found ) { 5. middle =(start - end)/2; 6. if (key > table[middle]) { 7. start = middle +1; 8. } else if (key == table[middle]) { 9. found = true; 10. LOC = middle; 11. } else 12. end = middle -1; 13. } 14. } //TestCase1 table={10, 20, 30, 40, 50, 60, 70}, key=55 //TestCase2 table={10, 20, 30, 40, 50, 60, 70}, key=40
  22. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    29 3,4. Test Yourselves (solution) 1. start =0; 2. end = 6; 3. found = false; 4. while (start <= end && ! found ) { 5. middle =(start - end)/2; 6. if (key > table[middle]) { 7. start = middle +1; 8. } else if (key == table[middle]) { 9. found = true; 10. LOC = middle; 11. } else 12. end = middle -1; 13. } 14. } //TestCase1 table={10, 20, 30, 40, 50, 60, 70}, key=55 //TestCase2 table={10, 20, 30, 40, 50, 60, 70}, key=40
  23. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    30 3,4. Test Yourselves (solution) 1. start =0; 2. end = 6; 3. found = false; 4. while (start <= end && ! found ) { 5. middle =(end - start)/2; 6. if (key > table[middle]) { 7. start = middle +1; 8. } else if (key == table[middle]) { 9. found = true; 10. LOC = middle; 11. } else 12. end = middle -1; 13. } 14. } //TestCase1 table={10, 20, 30, 40, 50, 60, 70}, key=55 //TestCase2 table={10, 20, 30, 40, 50, 60, 70}, key=40 //TestCase2 table={10, 20, 30, 40, 50, 60, 70}, key=40
  24. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    31 1. if (x<10 || y >50) 2. System.out.println("A"); 3. else 4. System.out.println("B"); 5. if (w==50 || z>10) 6. System.out.println("C"); 7. else 8. System.out.println("D"); Statement Coverage, Decision Coverage, and Decision-Condition Coverage with: //TestCase1 x=0, y=0, z=0, w=0 //TestCase1 x=11, y=75, z=50, w=12 //TestCase1 x=5, y=15, z=10, w=5 //TestCase1 x=15, y=75, z=50, w=3 5. Test Yourselves
  25. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    32 1. if (x<10 || y >50) 2. System.out.println("A"); 3. else 4. System.out.println("B"); 5. if (w==50 || z>10) 6. System.out.println("C"); 7. else 8. System.out.println("D"); Statement Coverage, Decision Coverage, and Decision-Condition Coverage with: //TestCase1 x=0, y=0, z=0, w=0 //TestCase1 x=11, y=75, z=50, w=12 //TestCase1 x=5, y=15, z=10, w=5 //TestCase1 x=15, y=75, z=50, w=3 5. Test Yourselves (solution)
  26. jgs

  27. jgs CSC 309 Software Engineering II Lab 12: Coverage Dr.

    Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227 Office Hours: By appointment
  28. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    36 Let’s Work 1* Continue Sprint 02 2* Consider adding test cases and 3* Report coverage during the Sprint presentation
  29. jgs CSC 309 Software Engineering II Javier Gonzalez-Sanchez, Ph.D. [email protected]

    Winter 2023 Copyright. These slides can only be used as study material for the class CSC308 at Cal Poly. They cannot be distributed or used for another purpose.