Skip to content

JUnit testing

Matthew Daley edited this page Mar 10, 2024 · 1 revision

JUnit Platform Console Standalone 1.6.2

Java unit testing is made simple with Judge0 extra CE using JUnit Platform Console Standalone 1.6.2 natively. The only change we had to make was to run each submission as a "Multi-file program" that requires a compile and run command in the form of bash scripts that are as follows:

Compilation Script

/usr/local/openjdk14/bin/javac -cp /usr/local/junit-platform-console-standalone-1.6.2/launcher.jar:. MainTest.java

Execution Script

/usr/local/openjdk14/bin/java -jar /usr/local/junit-platform-console-standalone-1.6.2/launcher.jar --disable-ansi-colors --disable-banner -cp . -c MainTest

These commands are tailored to ensure seamless integration with Judge0 Extra CE. By compiling and running each submission as a "Multi-file program," the setup ensures that submissions remain unaltered during execution, preserving the original run expectations and eliminating the need to address edge cases.


Student submissions

Student submissions are not altered in this process, the only thing instructors have to do to use unit testing is provide the code they want executed inside of each test. For example, if the students are tasked with creating a calculator that can add two numbers together, a test case might look like:

assertEquals(4, calculator.add(3, 1));

This example scenario can be found here.

Clone this wiki locally