🪶Grading with Maven

Overview

This guide shows how to set up a Maven-based Java programming assignment in CodeGrade, using instructor-written JUnit tests and AutoTest for automated grading.


Configuring AutoTest Setup

Install Java and Maven

In AutoTest > Setup:

  • Add the Install Java block (or use the script below).

  • Add a Script block to install Java 17, Maven 3.8.4, and junitparser:

sudo apt update
sudo apt install openjdk-17-jre -y

wget https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz -P /tmp/
sudo tar xf /tmp/apache-maven-3.8.4-bin.tar.gz -C /opt
sudo ln -s /opt/apache-maven-3.8.4/ /opt/maven
sudo rm /usr/bin/mvn
sudo ln -s /opt/maven/bin/mvn /usr/bin/mvn

pip3 install junitparser
AutoTest Setup for Maven assignments

Configuring AutoTest Tests

1. Upload and prepare instructor tests

  • Upload your test files using an Upload Files block (e.g., CircleTest.java).

  • Use a Script block to move them:

circle-exclamation
Upload and prepare tests

2. Prepare build and classpath

Add a Script block to compile and collect dependencies:

circle-info

This ensures all compiled classes and dependencies are available to the test phase.

3. Running Maven tests

Use Connect Rubric + Custom Test blocks for each test class. Each test block can link to a separate rubric category for grading.

circle-info

The project is compiled during the setup phase. Maven automatically skips recompilation when there are no changes.

Running Maven tests

Troubleshooting Maven Autograding in CodeGrade

This section lists common issues you may encounter when setting up Maven-based Java assignments in CodeGrade, along with quick solutions.

chevron-rightMaven or Java not foundhashtag

Symptom: AutoTest logs show mvn: command not found or java: command not found

Fix:

  • Ensure Java and Maven are installed in the Setup phase.

  • Double-check the setup script includes the correct symbolic links to Maven:

chevron-rightTests not detectedhashtag

Symptom: Maven runs without executing any tests.

Fixes:

  • Ensure test class names match *Test.java or *Tests.java.

  • Confirm test files are copied into src/test/java/...

  • If tests use packages, ensure folders match package structure.

  • Use the -Dtest=ClassName flag to target specific test classes in test blocks.

chevron-rightTest failures without outputhashtag

Symptom: AutoTest runs but doesn’t show detailed feedback.

Fix:

  • Verify cg junitxml target/surefire-reports/*.xml is included after mvn test.

  • Ensure the Surefire plugin outputs XML (default behavior).

  • Avoid cleaning (mvn clean) between test blocks unless needed.

chevron-rightClasspath errors or missing dependencieshashtag

Symptom: ClassNotFoundException or build errors for imported classes.

Fixes:

  • Run mvn dependency:copy-dependencies -DincludeScope=test in Setup.

  • Confirm your pom.xml includes required dependencies.

  • Use the environment setup script to populate CLASSPATH.

chevron-rightTimeouts or hanging testshashtag

Symptom: Tests hang or AutoTest fails due to long execution.

Fixes:

  • Use JUnit timeouts (e.g., @Test(timeout = 2000) or assertTimeout() for JUnit 5).

  • Review student code for infinite loops or blocking I/O.

  • Set step-level timeouts in AutoTest test block settings.

Still Need Help?

For assistance with custom cases, reach out to [email protected] and share a relevant snapshot or example submission.

Last updated