Link Search Menu Expand Document

Testing and debugging

Last day for on-time checkoff: Tuesday, 10/28

Prelab due 10/20/25 at 1:00 pm

Writeup due 10/27/25 at 1:00 pm

About

In this lab, you will come up with test cases to test your lab 5 code, based on a reference FSM. You will run these test cases and use the tests to debug your code. You will then be asked to reflect on the assumptions we made in testing. By the end of this lab, you will have seen how FSM-driven design influences unit testing for an embedded project.

Lab 6 Rubric

Resources

Materials

Same circuit as for Lab 5.

Steps

  1. Make sure that you still have your circuit and code from Lab 5, and follow these steps to set your code up for testing:

    1. We’ve made some changes to the stencil since lab 5. These are not files you modified in lab 5, so you should be able to copy the changes into your existing code without breaking anything. Add snakeTests.ino to the same folder as all files in the sketch, and copy over the new snakeUtils.ino as well.

    2. In snake.h, add the following line to the top of the file:

       #define TESTING
      
    3. In lab5.ino, add the following lines to the end of your setup() function:

       testAll();
       while(true);
      
    4. Compile your code (Sketch -> Verify/Compile or the checkmark button next to the upload button). Your Arduino does not need to be plugged in to complete this step. If there are compilation errors, double-check the steps above.

  2. Read the testTransition function in lab5_tests.ino and discuss how it works with your partner.

  3. Work with your partner to combine your test case tables. For most transitions and non-transitions, choose one partner’s test case to keep. For four transitions of your choice, include both tests, such that you have 22 tests in total. To create more rows in the testing table, highlight the two sheet rows that make up one transition entry. Copy the rows. Right-click on the next blank row and select “Paste special -> Paste format only”) Make sure that the tests are numbered from 0 to 21, in order, in column A.

  4. Follow the instructions at the end of the prelab to turn your test cases into lines of Arduino code. Remember that your spreadsheet shouldn’t have any invalid input errors nor blank cells in order for this code to work. Also check the pinned troubleshooting post on Ed if the script won’t run. Paste the generated lines from cell B1 into lab5_tests.ino under the REPLACE THE FOLLOWING 4 LINES WITH YOUR TEST CASES comment. You will probably have to remove some quotation marks that Google Sheets automatically adds on to copied cells.

  5. Connect your Arduino, open the Serial Monitor, and upload and run the code. If you get to “All tests passed!”, congratulations. Get checked off by a TA. Be prepared for your TA to ask you conceptual questions about your test cases. Otherwise, debug your code, based on which transition fails. You may find that there is a flaw in your implementation, or you may find that your test case made an incorrect assumption. In the second case, you should correct your assumptions (asking a TA if need be), modify the test case, and re-parse your test cases as in step 4 above.

  6. Comment out the #define TESTING line in snake.h; and remove the testAll()/while(true) lines in lab5.ino. Run your code and verify that the game plays as intended. If not, discuss what might have gone wrong and work on debugging your test cases and code (note that testTransition does not test that you called the outputs correctly, so even if your tests are correct and all pass, you should double-check that the outputs are being set correctly in each transition). Once the game is working, get it checked off by a TA.

  7. Turn in the code (entire Arduino project zipped up) on the Lab 6: Code Gradescope assignment