Adding tests to check exercise solution
To enable automatic checking of a learner's solutions to your exercises, you need to create automatic tests for each exercise.
If an exercise contains several instructions or conditions (for example, step 1, step 2, and so on), each instruction must have a test to check that its solution is correct. If you generate a blank exercise automatically, the number of test files generated will be equal to the number of instructions you specify.
Test formats
There are two types of tests:
- Input tests — these tests contain a set of input strings and expected output sepatared by #####. See Creating input tests for the details on the input tests format.
- Unit tests — these tests contain values for expected output.
Creating test files
To add tests to your exercise:
- Create a file named in this format: {exercise_name}_tests.py or {exercise_name}_tests.js (or with other extention depending on the programming language of the lab).
- Add to the file a content with criteria to check if a learner has successfully passed a test.
Test settings depending on exercise type
Configuring test settings varies based on the exercise type:
For multi-step exercises, specify in the exercise file which test applies to each step. See Adding tests for multi-step exercises for more details.
For single-step exercises, specify in the exercise-config.json file which test file to use for the entire exercise. See Adding tests for single-step exercises.
Before you publish your lab, ensure that your tests operate correctly.