$30 off During Our Annual Pro Sale. View Details »

CSC309 Lecture 08

CSC309 Lecture 08

Software Engineering II
Test Coverage
(202301)

Javier Gonzalez-Sanchez
PRO

January 26, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSC 309
    Software Engineering II
    Lecture 08:
    Test Coverage
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

  2. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 3
    § Validation. It is about requirements. Are we building the right product? Does
    this software do what it needs to do?
    § Verification. It is about design. Are we building the product right? Does this
    meet its requirements?
    § Testing. Examination of the behavior of a program by executing it on
    sample data sets.
    Definition

    View Slide

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

    View Slide

  4. jgs
    Test Coverage

    View Slide

  5. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 6
    Testing
    White Box
    (Verification)
    Unit Testing
    Integration Testing
    Black Box
    (Validation)
    System Testing
    Scenario-based
    testing
    Model-based testing
    Testing

    View Slide

  6. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 7
    § 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

    View Slide

  7. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 8
    Example

    View Slide

  8. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 9
    Example

    View Slide

  9. jgs
    Software Testing
    Coverage

    View Slide

  10. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 11
    § Statement Coverage: every statement is executed at least 1 time.
    § Decision Coverage: every decision point is executed at least 1 time
    § Decision-Condition Coverage: every decision tested with all possible
    outcomes
    Coverage

    View Slide

  11. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 12
    Example

    View Slide

  12. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 13
    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

    View Slide

  13. jgs
    Test Yourselves
    Coverage

    View Slide

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

    View Slide

  15. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 16
    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;
    Total Statements?
    Statement Coverage with a = 0, b=0, w=0, y=0 ?
    Statement Coverage with a=10, b=4, w=5, y = anything ?
    Note: Remember that coverage is cumulative
    Test Yourselves

    View Slide

  16. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 17
    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. }
    //TestCase1 table={10, 20, 30, 40, 50, 60, 70}, key=55
    //TestCase2 table={10, 20, 30, 40, 50, 60, 70}, key=40
    Test Yourselves

    View Slide

  17. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 18
    Let’s Work

    View Slide

  18. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 19
    Questions

    View Slide

  19. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 20
    Office Hours
    Tuesday and Thursday 3 - 5 pm
    But an appointment required
    Sent me an email – [email protected]

    View Slide

  20. jgs

    View Slide

  21. jgs
    CSC 309
    Software Engineering II
    Lab 08:
    Coverage
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

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

    View Slide

  23. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 24
    One More For Homework

    View Slide

  24. 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.

    View Slide