☕Grading Java package projects
More advanced Java assignments often ask students to organise their code into packages. When a student's code lives under a package such as myapp, any instructor tests you want to run against it must sit inside the same package folder so that javac and JUnit can resolve the imports correctly.
This guide walks through the pattern: upload the instructor's JUnit 5 test file, compile the student's code, move the test into the student's package folder, and run it.
Step 1: Install JUnit 5
Before setting up your tests, you need to install JUnit5 in the AutoTest environment.
Navigate to the Setup tab under the AutoTest settings.
Add a Script block and paste the following:
cg junit5 installStep 2: Compile the student code and place the instructor tests
Navigate to the Tests tab under the AutoTest settings.
Add an Upload Files block and attach your instructor test file (e.g.
CalculatorTest.java).Add a Script block immediately after and paste the following:
#!/usr/bin/env bash
cg java compile $STUDENT/myapp/*.java
mv $UPLOADED_FILES/*.java $STUDENT/myappStep 3: Run the JUnit 5 tests
Add a Connect Rubric block and select the appropriate rubric category from the drop-down menu.
Add a Custom Test block and nest it within the Connect Rubric block.
Paste the following into the editor:
If your students organise their work across multiple packages, adjust the classpath entries and the --select-class argument accordingly — for example, myapp.utils.StringUtilsTest.
Conclusion
You have set up an automatically graded assignment that handles package-structured student code. Explore more details on JUnit5 in CodeGrade or on running Checkstyle alongside your tests. For any questions about custom setups, reach out to our support team at support@codegrade.com.
Last updated