Salut,
Alors dans un cours sur les tests unitaires on a vu le framework Mockito, mais je sais pas, j'ai vraiment un problème je pense : j'arrive absolument pas à comprendre ce que ça fait, à quoi ça sert, bref je comprends pas Mockito
Sur Wikipedia j'ai trouvé un exemple relativement simple : http://en.wikipedia.org/wiki/Mockito#Example mais rien à faire, je bloque sur les méthodes de Mockito, par exemple il y a ça :
@Before
public void setUp() {
helloGreeterMock = mock(Greeter.class);
helloWriterMock = mock(Appendable.class);
helloAction = new HelloAction(helloGreeterMock, helloWriterMock);
}
@Test
public void testSayHello() throws Exception {
when(helloWriterMock.append(any(String.class))).th
enReturn(helloWriterMock);
when(helloGreeterMock.getIntroduction(eq("unitTest
"))).thenReturn("unitTest
: ");
when(helloGreeterMock.getGreeting(eq("world"))).th
enReturn("hi
world");
helloAction.sayHello("unitTest", "world");
verify(helloGreeterMock).getIntroduction(eq("unitT
est"));
verify(helloGreeterMock).getGreeting(eq("world"));
verify(helloWriterMock, times(2)).append(any(String.class));
verify(helloWriterMock, times(1)).append(eq("unitTest : "));
verify(helloWriterMock, times(1)).append(eq("hi world"));
}
mais je capte juste pas, qu'est-ce qui est testé dans testSayHello ? C'est quoi le résultat attendu ? Comment on sait qu'on a eu ce bon résultat ? Ca fait quoi ce verify chelou ?
On est pas obligés de l'utiliser mais ce truc c'est une vraie énigme pour moi là, j'arrive absolument pas à voir ce que fait le framework...
Quelqu'un pour m'expliquer concrètement ce que ça fait ici ?