Automatic assessment of code questions

It is possible to automatically assess code question based on unit test. This works as follows.

On the Assessment tab of the code question, add a Unit test action. For each unit test, make sure it has a clear name, for example unitTest1, unitTest2, and so on. Under Show more you might want to switch on Hide feedback. But if you still want to see the results of the unit tests when looking at the submission, you can leave it off.

Now add a Code action below it. In this code action you can inspect the values of the properties qf.unitTest1, qf.unitTest2, and so on. They are true or false, depending on whether the test was successful or failed. Now you can change the property qf.score based on those values, to change the score. For example, you can write

qf.score = 100;<br>if (!qf.unitTest1) qf.score -= 50;<br>if (!qf.unitTest2) qf.score -= 50;

This will give a score of 100 when both test succeed, 50, when only one test succeeds, and 0 when no test succeeded.

You can also use qf.successfulTestCount that indicated the number of successful unit tests and qf.failedTestCount that indicates the number of failed unit tests. So for example you can use:

if (!qf.failedTestCount === 0) qf.score = 100;<br>else if (!qf.failedTestCount === 1) qf.score = 50;<br>else qf.score = 0;

This will give full points when all tests succeed, 50 points when just one test fails, and no points when more tests fail.

Still need help? Contact Us Contact Us