block-quote On this pagechevron-down
copy Copy chevron-down
Automatic Grading Guides chevron-right ☕ Java🪶 Grading with MavenThis 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:
Copy 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
Block student-submitted test files in General Settings > Hand-in Requirements (e.g., deny *Test.java).
2. Prepare build and classpath
Add a Script block to compile and collect dependencies:
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.
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-right Maven or Java not found hashtag 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-right Tests not detected hashtag 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-right Test failures without output hashtag 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-right Classpath errors or missing dependencies hashtag 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-right Timeouts or hanging tests hashtag 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 2 months ago