Learn How to Auto-Grade

Auto-grading is a powerful tool that saves teachers time and provides students with feedback regarding the correctness of their solution before they submit it for a grade.

All of this auto-grading magic can be accomplished with unit testing -- test whether parts (units) of a students code work properly by asserting that they meet certain conditions (equal to a predetermined value, produce a result in a given range, etc.).

Assertions and Unit Testingchevron-right🐍Python Exampleschevron-rightβ˜•Java Exampleschevron-rightπŸ’ŽRuby Exampleschevron-right

Webinar

Quick Start

New to Unit Testing? Let's do a brief review.

TODO

Python - unittest

The basic building blocks of unit testing are test cases β€” single scenarios that must be set up and checked for correctness.

The simplest TestCasearrow-up-right subclass will simply implement a test method (i.e. a method whose name starts with test) in order to perform specific testing code:

Note that in order to test something, we use one of the assert*() methods provided by the TestCasearrow-up-right base class. If the test fails, an exception will be raised with an explanatory message, and unittestarrow-up-right will identify the test case as a failure. Any other exceptions will be treated as errors.

Tests can be numerous, and their set-up can be repetitive. Luckily, we can factor out set-up code by implementing a method called setUp()arrow-up-right, which the testing framework will automatically call for every single test we run:

Similarly, we can provide a tearDown()arrow-up-right method that tidies up after the test method has been run:

If setUp()arrow-up-right succeeded, tearDown()arrow-up-right will be run whether the test method succeeded or not.

Java - JUnit

TODO

Created and curated by Joe Mazzone

Joe Mazzonearrow-up-right, former Computer and Software Engineering instructor at William M. Davies, Jr. Career and Technical High Schoolarrow-up-right in Lincoln, Rhode Island.

Joe is now a Senior Product Manager/Product Development Lead at John Wiley & Sons, Inc., working on Coding Roomsarrow-up-right and zyBooksarrow-up-right.

Like what Joe created? β˜• Buy him a coffee: https://www.buymeacoffee.com/JoeMazzonearrow-up-right

Last updated

Was this helpful?