Предположим, что у меня есть класс ниже, простой класс, чтобы добавить три строки в String ArrayList с именем ar.Испытание Junit на ArrayList
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);
}
}
Как я могу использовать тестирование Junit, чтобы убедиться, что строки действительно вошли в ArrayList?
Update
Мой TestcasesTest файл - где производится тестирование, выглядит следующим образом:
@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());
}
}
Создайте массив, содержащийся в g значения для проверки, затем пройти каждое значение и проверить, что возвращаемый 'ArrayList' имеет одинаковую длину и значения этого массива. –
Эй! Я добавил код в OP. Я создал новый массив 1D и заполнил его. Я просто не уверен, как сравнивать ArrayList и Array. –