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

CSC309 Lecture 18

CSC309 Lecture 18

Software Engineering II
Test Driven Development
(202305)

Javier Gonzalez-Sanchez
PRO

February 23, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSC 309
    Software Engineering II
    Lecture 18:
    Test Driven Development
    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
    § Final Exam
    Wednesday, June 14 at 1:10 pm
    https://registrar.calpoly.edu/spring-final-exam-schedule
    § Final Project
    Friday, June 09 (lecture Time)
    § Academic Holiday
    Monday, May 29 (lecture Time)
    § Project Status Report 3
    Friday, May 26 (lecture Time)
    Schedule

    View Slide

  3. jgs
    Previously …

    View Slide

  4. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 5
    int x;
    void student () {
    world();
    for (int x=0; x<10; x++) {
    hello(); x = x + 1; break;
    }
    }
    Case 4
    Input:
    Output:

    View Slide

  5. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 6
    Objects
    Begin
    End
    Call a method
    Instruction
    Input or Output
    Variable declaration
    Condition

    View Slide

  6. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 7
    1. Create a GUI
    2. Develop a Lexer that splits and classifies words
    3. A parser method for method
    4. A parser method for local variables
    5. A parser method for instructions
    6. A parser method for input/output (println)
    7. A parser method for the if condition
    8. A parser method for the for loop
    9. Test Cases for Lexer
    10. Test Cases for Parser
    Issues

    View Slide

  7. jgs
    Unit Testing

    View Slide

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

    View Slide

  9. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 10
    Definition
    Testing a unit - the smallest
    piece of code that can be
    logically isolated in a system.
    (a method in Java)

    View Slide

  10. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 11
    Definition
    TDD suggests that the code is
    developed or changed exclusively
    on the basis of Unit Testing.

    View Slide

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

    View Slide

  12. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 13
    Source Code

    View Slide

  13. jgs
    Test-Driven Development

    View Slide

  14. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 18
    TDD

    View Slide

  15. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 19
    § You cannot test every possible input, parameter value, etc.
    So, you must think of a limited set of tests likely to expose bugs.
    § Think about boundary cases
    positive; zero; negative numbers
    right at the edge of an array or collection's size
    § Think about empty cases and error cases
    0, -1, null; an empty list or array
    § Test behavior in combination
    maybe add usually works but fails after you call to remove
    make multiple calls; maybe the size fails the second time only
    Tips for Testing

    View Slide

  16. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 20
    § Test one thing at a time per test method.
    10 small tests are much better than 1 test 10x as large.
    § Each test method should have a few (likely 1) assert
    statements.
    If you assert many things, since the first that fails will stop the
    test, you won't know whether a later assertion would have
    failed.
    § Torture tests are okay, but only in addition to simple tests.
    Trustworthy tests

    View Slide

  17. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 21
    Questions

    View Slide

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

    View Slide

  19. jgs

    View Slide

  20. jgs
    CSC 309
    Software Engineering II
    Lab 18:
    Test Driven Development
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    Building 14 -227
    Office Hours: By appointment

    View Slide

  21. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 26
    Scenario
    Box
    Name1
    Name2
    class Name1 {
    }
    class Name2 {
    method(){
    Name1
    Cat
    }
    }
    class Cat
    extends Name1 {
    }
    Cat

    View Slide

  22. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 27
    Let’s Work

    View Slide

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