Bonjour,
J'ai un souci pour tester une fonction de classe en java avec JUnit4.
voila la classe :
J'ai crée ce test unitaire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import java.util.ArrayList; public class Liste { public static ArrayList<ArrayList<Integer>> fct (ArrayList<Integer> liste, Integer taille){ ArrayList<ArrayList<Integer>> List = new ArrayList<ArrayList<Integer>>(); ArrayList<Integer> list = new ArrayList<Integer>(); int i=0,j=0,k=0; while (i<liste.size()) { list.clear(); for ( j = 0; j < taille; j++) { if((j+i)<liste.size()) list.add(liste.get(i+j)); } List.add((ArrayList<Integer>) list.clone()); i+=taille; k++; } return List; } }
Mais le test ne marche pas !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import static org.junit.Assert.*; import java.util.ArrayList; public class test { @org.junit.Test public void testListe(){ ArrayList<Integer> l1 = new ArrayList<>(); for (int i = 0; i < 15; i++) { l1.add(i); } assertEquals(l1, Liste.fct(l1, 5)); } }
PS : j'ai ajouter les jar suivants au projet : hamcrest-core-1.3-sources.jar et junit-4.12.jar
Merci de vos aides
Partager