EX14 - Unit Testing


Overview

In Exercise 14, you will write some unit tests for the functions we define together in class on 6/14. This will give you practice with writing test cases and thinking about the use case and edge cases of an algorithm. Anytime you write code, it is important to sketch out expected behavior and results. Unit testing helps you verify functionality and helps locate bugs in need of attention.

0. Pull the skeleton code

You will find the starter files needed by “pulling” from the course workspace repository. Before beginning, be sure to:

  1. Be sure you are in your course workspace. Open the file explorer and you should see your work for the course. If you do not, open your course workspace through File > Open Recent.
  2. Open the Source Control View by clicking the 3-node (circles) graph (connected by lines) icon in your sidebar or opening the command palatte and searching for Source Control.
  3. Click the Ellipses in the Source Control pane and select “Pull” from the drop-down menu. This will begin the pulling process from the course repository. It should silently succeed.
  4. Return to the File Explorer pane and open the exercises directory. You should see it now contains the directory named ex14. If you expand those directories, you will see the starter files for this exercise.

If the above did not work, try the following:

  1. Click the Ellipses in the Source Control pane and select “Pull, Push” from the drop-down menu. Then select “Pull from”. Then select “upstream” and the main option. This will begin the pulling process from the course repository. It should silently succeed.
  2. Return to the File Explorer pane and open the exercises directory. You should see it now contains another directory named ex14. If you expand that directory, you should see the starter files If you expand that directory, you will see the starter files: list_utils.py and list_utils_test.py.

1. Starter Files

Your work in this exercise will be completed across two files:

  1. list_utils.py - This is the Python module where your list utility functions are implemented. We will define these together in class on Monday June 14th, however, you are welcome to add more if you are interested!

  2. list_utils_test.py - This is the python file that will house all of the unit tests for this exercise. One basic test is already included.

For each function from class (all, max, sub, concat), you are to define 3x unit test functions. Remember that a unit test function starts with test_. In order for our grader to execute correctly, import these functions using the complete path. This should look like from exercises.ex14.list_utils import max, all, sub, concat.

The 3 unit tests should consist of:

  • One edge case
  • Two use cases

We will be hand-grading for the appropriate inclusion of use vs. edge cases.

Include descriptive function names and docstrings like we saw in class so that it captures what is being tested.

The command to run your tests is python -m pytest exercises/ex14 or you can run them using the beaker tab in VSCode if it is working (it tends to be a bit flaky).

If your screen is large enough, you are encouraged to open these files side-by-side in VSCode by dragging the tab of one to the right side of VSCode so that it changes to a split pane view. Closing your file explorer can help give you additional horizontal space.

Autograding

Login to Gradescope and select the assignment named “EX14 - Unit Testing”. You’ll see an area to upload a zip file. To produce a zip file for autograding, return back to Visual Studio Code.

If you do not see a Terminal at the bottom of your screen, open the Command Palette and search for “View: Toggle Integrated Terminal”.

To produce a zip file for ex14, type the following command (all on a single line):

python -m tools.submission exercises/ex14

In the file explorer pane, look to find the zip file named “21.mm.dd-hh.mm-exercises-ex14.zip”. The “mm”, “dd”, and so on, are timestamps with the current month, day, hour, minute. If you right click on this file and select “Reveal in File Explorer” on Windows or “Reveal in Finder” on Mac, the zip file’s location on your computer will open. Upload this file to Gradescope to submit your work for this exercise.

Autograding will take a few moments to complete. For this exercise there will be 10 points manually graded to coverage of edge and use cases. If there are issues reported, you are encouraged to try and resolve them and resubmit. If for any reason you aren’t receiving full credit and aren’t sure what to try next, come give us a visit in office hours!