For my assignment, I have to develop several jUnit tests for the method:
addAll(int index, Collection c)
This method is part of the class ArrayList – built in to java.
I figured out how to create the tests and run them in Eclipse IDE, but I’m a little confused as to exactly how I’m supposed to develop the tests. Could I get an example that includes what I should have in a @before, @beforeClass, @after, @test method?
To make this clear, I understand the format of the methods…I just don’t understand HOW to test this method.
So, what you need to test is that the method inserts all the elements in the passed Collection and that it inserts them into the appropriate position in the ArrayList.
Think of all the possible senerios and test each one.
After the add, verify / assert that the ArrayList now has all the elements that it should have in the correct order / locations.
Also test the error cases with @Test(expected=…).
Also… assertThat in combination with Hamcrest’s IsIterableContainingInOrder would be helpful for verification.