1 of 19

Testing & Static Analysis

Fall 2024

1

2 of 19

Announcements

  1. We will be starting on Project 1 in class on Thursday – due after the break.
  2. Mid-term exam next Thursday
  3. I forgot to post the readings, but they’re posted now. Please read the Testing and Static Analysis Chapters in the Google Book. We will discuss them on Thursday.

3 of 19

Today’s Agenda

  1. Testing Overview
  2. Static Analysis Overview
  3. Activity 1: Testing & Static Analysis
  4. Activity 2: Software Design

3

4 of 19

Today’s Agenda

  • Testing Overview
  • Static Analysis Overview
  • Activity 1: Testing & Static Analysis
  • Activity 2: Software Design

4

5 of 19

Warmup: Benefits of Testing

What are some of the benefits of automated testing?

6 of 19

Benefits of Automated Testing

What are some of the benefits of testing?

  • Less debugging
  • Increased confidence in changes – Why?
  • Improved documentation – Why?
  • Simpler reviews – Why?
  • Thoughtful design – Why?
  • Fast, high-quality releases – Why?

7 of 19

Today’s Agenda

  • Testing Overview
  • Static Analysis Overview
  • Activity 1: Testing & Static Analysis
  • Activity 2: Software Design

7

8 of 19

Static Analysis

  • What is a Compiler?
  • What languages are compiled?
  • Do JavaScript and Python have compilers?
  • What is an Interpreted Language?

9 of 19

Static Analysis

  • What do we mean by "Static"?
  • Static-Analysis
    • Tools that examine and evaluate code without actually running it
  • Autoformatters
    • Focuses on formatting code automatically, enforcing style consistency (e.g., Black)
  • Linters
    • Focuses on analyzing code for possible errors, style violations, or inefficiencies, but typically leaves the code unchanged (e.g., Flake8)
  • Trade-offs

10 of 19

Today’s Agenda

  • Testing Overview
  • Static Analysis Overview
  • Activity 1: Testing & Static Analysis
  • Activity 2: Software Design

10

11 of 19

  • On GitHub, sync your fork
  • On your local machine:
    • Navigate to your csci338/class-exercises-fall2024 directory
    • Check that everything is already committed and pushed to your remote branch
    • Checkout main
    • Pull down the latest code (git pull)
  • Do the activity

12 of 19

Today’s Agenda

  • Testing Overview
  • Static Analysis Overview
  • Activity 1: Testing & Static Analysis
  • Activity 2: Software Design

12

13 of 19

Project 1: What the app should do

For your first project, you are going to create a command line tool to replicate aspects of the UNCA Course Search app. You and your team will implement the following features:

  • A way to download the UNCA data file from the Internet (JSON)
  • A way to display the search options.
  • A way to allow the user to specify which search options / filters they want
  • A way to store the user’s preferences (for any of the options)
  • A way to filter the courses according to the user’s preferences
  • A way to view, add and remove courses from a user’s schedule
  • A way to email their schedule to themselves

DEMO

14 of 19

What are some things you need to think about?

As a group, you need to organize your code so that everyone can make progress in parallel. What are some things you can do to make life easier?

  • Divide and conquer
  • Every person work on a different part
  • How to manage merges
  • Timeline

15 of 19

Tips

  • Single Responsibility Principle: A class should only have one job.
  • DRY Principle: Don’t repeat yourself.
  • Optimize for code readability rather than for performance: Why?

Make it correct,� make it clear,� make it concise,� make it fast.� In that order.

  • Delete unused code

16 of 19

Tips

  • Be deliberate with your naming – Name your classes, methods, class variables and even local variables very semantically.
  • Change one thing at a time – You don’t want a pull request that’s 1,000 lines long. Nightmare to review. Rather, make smaller PRs that have changes that are clear and easy to review / understand.
  • Write “dumb code”
    • “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
  • Beyoncé Rule – put a test on it; write testable code

17 of 19

Activity: On Your Own (10 mins)

  • Take out a piece of paper
  • Write down all of the classes you will need to create to build your course lookup app.
    • For each class, think about the properties and methods that will be needed.
    • Think about how you would make those classes testable.
  • Think about what could you do today to…
    • Make this project maintainable over time?
    • Minimize merge conflicts

18 of 19

Activity: In Groups of 4 (10 mins)

  • Discuss your designs with one another?
  • What was similar or different?

When you’re done, you’ll share out with the class.

19 of 19

We will continue this activity on Thursday