Slide 1

Slide 1 text

jgs CSC 309 Software Engineering II Lecture 12: Test Coverage Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227

Slide 2

Slide 2 text

jgs Sprint 2

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 8 Compare Sprint 1 and Sprint 2

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 10 Do not Do This

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

jgs Test Coverage

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 17 Example

Slide 18

Slide 18 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 18 A cumulative metric

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

jgs Test Yourselves Coverage

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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)

Slide 33

Slide 33 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 33 Questions

Slide 34

Slide 34 text

jgs

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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.