Code editor questions written in Python can be automatically tested and graded. This allows you to define test cases that are used to evaluate the correctness of a student’s code submission. By automating the grading process, you save time and ensure consistent feedback based on predefined criteria. The test criteria are defined as Pytest unit tests, and can award points per passed test. If the feature Run Live Code [Add-on] is also enabled, participants can test their code during the digital test.
To use automated testing for a code editor question, follow the steps below.
- Navigate to your code editor question or create one.
- Click on the Grading scheme tab.
- Click the more_horiz-icon in the question and click Edit.
- Set the grading type to 'Use automated testing'.
Participants' code can be automatically tested and graded in two ways: via a pre-existing Pytest file or manually adding the tests to the grading scheme. Student answers can automatically be graded by using the assert
statement in the testing files.
Pytest file
If you want to use a pre-existing Pytest file, it is possible to upload this. You can download a template file after clicking on Upload testing file. This also allows you to make use of Python libraries or define Pytest fixtures to use during testing. These can be defined in the imports and test fixtures field.
To upload a Pytest file, follow the steps below.
- Navigate to the grading scheme of your code editor question.
- Click on Upload testing files.
- Select or drag and drop the Pytest file.
- Click on Save.
Manually add test criteria
To add test criteria, follow the steps below.
- Navigate to the grading scheme of your code editor question.
- Click on the + icon.
- Fill in the Test method name. Please note that every Test method name must be unique
- Fill in the number of points.
- Fill in the Test contents. Please note:
- The
assert
statement needs to be used in the test contents. This is used to verify if the condition is true. If the condition is false, the test fails, and the student does not receive the points. - The name of the function that the student writes in their answer needs to be the same as in the Test contents. Therefore, the name of the function must be given to the student.
- The student must use the
def
statement to define the function. - The test logic, assertions and feedback messages are added in the code field. A criterion is considered correct if every test assertion passes.
- The
- Click on Save.
In the review screen, the automatically graded questions will be indicated with the auto_fix_high icon. The test criteria that the participant passed with their answer are selected.
If your school also uses the add-on Run Live Code and it is enabled in the assignment, participants can execute their code during the assignment to see whether it passes the predefined test cases. This helps them to get immediate feedback and make adjustments before submitting their final answer.
Comments
0 comments
Please sign in to leave a comment.