Necronet Necronet - 1 year ago 90
Java Question

Test login three times with mockito throws an Exception!

I have a test but i am not quite good with it, i want to verify that when the methods login is called three times with wrong username and password it throws an exception is this test correct:

public void testLogin_WrongUser_More_Than_Three_Times() {

System.out.println("Testing login With Wrong User More than three Times Method");

Login mock=mock(Login.class);

when(mock.login(username, password)).thenThrow(new TooManyLoginException("Ha intentado entrar demasiadas veces el programa se cerrara"));

for(int i=0;i<4;i++)
mock.login(username, password);


An example might be nice!!

Answer Source

In fact i found a clear explanation here

Now i do understand Mock objects.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download