Suppose that I have the below class, a simple class just to add three Strings into a String ArrayList named ar.
public class Testcases {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
public ArrayList<String> myArray() {
ArrayList<String> ar = new ArrayList<String>();
ar.add("Customer1");
ar.add("Customer2");
ar.add("Customer3");
return(ar);
}
}
How could I use Junit testing to make sure that the Strings actually went into ArrayList?
Update
My TestcasesTest file - where the testing is done, looks as follows:
@Test
public void testMain() {
System.out.println("main");
String[] args = null;
Testcases.main(args);
// TODO review the generated test code and remove the default call to fail.
// fail("the test case is a resul in the prototype");
}
/**
* Test of add method, of class Testcases.
*/
@Test
public void testMyArray() {
assertEquals(Arrays.asList("Customer1", "Customer2", "Customer3"), myArray());
}
}
ArrayListhas the same length and values of this array.