-
Debugging tips often seem pointless and obvious to students when they don’t currently have a bug they’re trying to fix.
-
At that moment a test case fails, students will need to start debugging.
-
They'll look at the specific JUnit test case when it fails, which gives you a just in time delivery model for debugging tips.
-
If there are debugging suggestions within each test case, you can direct students to effective debugging strategies when they really need them.
- Below is an example of JUnit tests with debugging tips embedded inside the test cases:
import java.util.Arrays;
import junit.framework.TestCase;
public class Hw4pr3Test extends TestCase {
// Examples of tips for debugging!
public void testAppend_3_3_length() {
int[] input1 = { 10, 20, 30 };
int[] input2 = { 40, 50, 60 };
int[] output = Hw7pr2.append(input1, input2);
assertTrue(output.length == 6);
// DEBUGGING: if this test case fails, try:
// -- printing out output.length to see if it is too small or too big.
// -- writing a simpler test case to see if the method works for simpler cases.
// -- running only this test case (double click on the test name and then click "Run") so that it is easier to see your print statements.
// -- adding print statements to the append method to see if it is behaving as you expect.
// -- setting a breakpoint inside the append method to see if it is behaving as you expect.
}// Examples of (well formatted) print statements that the students might use
public void testAppend_3_3() {
int[] input1 = { 10, 20, 30 };
int[] input2 = { 40, 50, 60 };
int[] correct = { 10, 20, 30, 40, 50, 60 };
int[] output = Hw7pr2.append(input1, input2);
// DEBUGGING: Remove comment for debugging (and double check variables being printed)
// System.out.println("*** testAppend_3_3 ***");
// System.out.println("input1: " + Arrays.toString(input1));
// System.out.println("input2: " + Arrays.toString(input2));
// System.out.println("correct:" + Arrays.toString(correct));
// System.out.println("output: " + Arrays.toString(output));
assertTrue(Arrays.equals(output, correct));
}
}