The Unit Test provides integration with unit testing frameworks that support JUnit XML output. The only input for this type of test is a command to be run, which must produce a JUnit XML file at the location stored in the
$CG_JUNIT_XML_LOCATION environment variable. Students will then get a clear overview of all the tests that have been run, which ones failed, and the output that was produced in the case of failure.
The resulting score of this step is the fraction of successful tests divided by the total number of tests that were run, multiplied by the weight of the test.
Unit Tests are useful if you want to run many tests but condense their output into a single entry in the test category. They are also useful when you already have a unit testing setup, and do not want to translate them all into individual AutoTest tests. Naturally, unit tests are a great way to assess individual functions and methods of larger programming assignments.
We provide wrapper scripts for a growing list of frameworks that handle everything for you, these are installed by default on AutoTest. If your unit testing framework is not in the list below, it is possible to manually create a small wrapper script for this to output the results in the correct location.
All wrapper scripts share a similar interface and procedure for running tests, which we describe below, replace
SCRIPT for the unit test script you want to use from the list above.
Installing: install the script in the global setup script to run by calling
Compiling: For compiled languages it can be tricky to get the compiler to find all libraries and other dependencies needed to compile the students’ code and your tests. For these languages the wrapper scripts provide a
compile command that configures the compiler to be able to find the required libraries. The
compile command takes file names as arguments and compiles those files. Run the command
cg-SCRIPT compile <file1> <file2> ...to compile the student code and test classes.
Running: The wrapper scripts run the unit tests with their
The scripts extract the output location from
$CG_JUNIT_XML_LOCATION and then unset it before running the tests. The testing framework is then configured to output its results at that location and the tests are executed. Run the command
cg-SCRIPT run <file1> <file2> ...to compile the student code and test classes.