开发者

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 开发者_JAVA百科an exception is this test correct:

@Test(expected=Login.TooManyLoginException.class)
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!!


Take a look at The Mockito documentation on multiple executions. It describes how you can get the mock to do a throw on the third request. Which is what I think you are after.


In fact i found a clear explanation here

http://schuchert.wikispaces.com/Mockito.LoginServiceExample

Now i do understand Mock objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜