Black-box testing can be kind of envisioned as input-output pairs. You give your program a set of inputs and see whether the outputs match what you expect.
So in this case, you'd have something like:
input: {5, 3, 1}; expected output: {1, 3, 5}
input: {9, 7, 5, 6, 8, 34, 3, 6}; expected output: {3, 5, 6, 6, 7, 8, 9, 34}
input: {} expected output: {}
input: {1, 3, 5} expected output: {1, 3, 5}
and you would use something like assertArrayEquals()
to check that the program's output is what you expect it to be.
White-box testing is a bit more involved, because you're designing tests that attempt to exercise all possible paths through the code, which mean that white box tests tend to be a bit more implementation-specific. To be honest, I'm not very familiar with white-box testing, so there isn't much I can help you with. I'm guessing that white-box testing for this would be essentially looking at your code and looking for the various corner cases that might pop up during execution. Your code does seem to be pretty straightforward though so I'm not sure what cases you might come up that wouldn't already be covered by black-box tests...
For the specific test you gave, I believe the issue is in this line:
assertArrayEquals(20, a.unsortedArray(x, 20));
assertArrayEquals()
either takes two arrays as arguments or a String
and two arrays, with the String
acting as the error message. I don't think your code would compile, as neither of the arguments you pass it are valid. In addition, you don't appear to define an unsortedArray(int[], int)
method... Did you mean to do selectSort2(x, 20)
?
Once you fix that line the JUnit test should work. Commenting out that one line allowed the JUnit test to run on my computer at least.
One more thing -- you said you wanted to test the size of the array in the SelectionSort class. For that, assertTrue()
might be the method to use, but I'm not sure such a test would be useful, because array sizes cannot be changed and you are not returning a new array at any point.