A Unit Test exercise lets students test their code against the Solution Code, or ‘right answer’, with a series of test inputs. This is helpful so that students can see whether or not their program is working across a diverse set of inputs. The input is passed into the student code, and into the teacher solution, and the result and difference is shown to the student. 

The ‘Expected Result’ is the result of putting the input into the solution code, and Your Result is the result of putting the input into the student’s code. 

To create a Unit Test exercise, head to the CMS, create a new exercise, and give it a Unit Test type. Then choose a language -- you can choose Java, JavaScript, or Python. 

Then, head over to the Code tab. Here, we can define the Starter Code (the code that a student sees the first time they open the program) and the Solution Code. The Solution Code has two purposes. It’s the official Teacher Solution that you and other teachers can reference for grading. The Solution Code also compares the result of the student’s code (when they run their code)  against the result of the Solution Code.

Usually, the Starter Code will provide a skeleton of the problem -- it’s helpful to provide a function with the correct name, that just returns the input. The Solution Code should solve the exercise. 

Now, head over to the Autograder tab in order to define your sample inputs. 

Click Add Test Case to begin adding your test cases. 

Make sure that when you add a new test case, you press Save Tests in order to save your progress.

You can select whether each input is ‘hidden’ or not. Hidden inputs just give a pass or failure message without showing the student the sample input, making it harder to ‘game’ the unit tests. 

If you’re having trouble, make sure that you have a single defined function present in your solution code. 

That’s it! Enjoy creating unit tests for your students. 

Did this answer your question?