Grading with JUnit
Codio allows you to easily use JUnit to grade student code. When creating an advanced code test, choose the language under the Execution
tab and then choose the unit testing framework you want.
Set the SOURCE PATH
field to the directory with the student file. This works best if all of the coding exercise files are in their own directory separate from other student files.
For ADD CASE
, drag the JUnit test file into the field.
Here is an example of a JUnit test. Note, each assert
statement has the variable feedback
which contains feedback for the student for each test case.
import static org.junit.Assert.*;
import org.junit.Test;
public class Exercise2Tester {
@Test
public void checkToString1() {
String[] members = {"Syd", "Nick", "Roger", "Richard", "David"};
Band band = new Band("Pink Floyd", "rock'n roll", members);
String expected = "Band[name=Pink Floyd, genre=rock'n roll, members=[Syd, Nick, Roger, Richard, David]]";
String actual = band.toString();
String feedback = "Output did not match.";
assertEquals(feedback, expected, actual);
}
@Test
public void checkToString2() {
String[] members = {"RZA", "GZA", "ODB", "Method Man", "Ghostface Killah", "Inspectah Deck", "U-God", "Masta Killa", "Cappadonna"};
Band band = new Band("Wu-Tang Clan", "hip hop", members);
String expected = "Band[name=Wu-Tang Clan, genre=rap, members=[RZA, GZA, ODB, Method Man, Ghostface Killah, Inspectah Deck, U-God, Masta Killa, Cappadonna]]";
String actual = band.toString();
String feedback = "Output did not match.";
assertEquals(feedback, expected, actual);
}
}