aspose file tools*
The moose likes Testing and the fly likes Mockito Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Mockito" Watch "Mockito" New topic
Author

Mockito

Kevin Simonson
Ranch Hand

Joined: Oct 22, 2011
Posts: 114
Is this the right forum to ask questions about Mockito? If so, is anyone aware of a good tutorial that would teach me how to use Mockito?

Kevin S
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

Kevin

I have moved your post to the Testing forum.

As for your question, I recently (in April) starting using Mockito and the best simple examples I found were:

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

http://www.javacodegeeks.com/2013/05/junit-and-mockito-cooperation.html

http://tutorial.fyicenter.com/out.php?ID=3966

FAQ: https://code.google.com/p/mockito/wiki/FAQ

Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

I think it may be better to start with the official guide.
http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html

There are few features which may need further google.
thenReturn vs doReturn
doReturn vs doAnswer
mock vc spy
captor
injectMocks
Kevin Simonson
Ranch Hand

Joined: Oct 22, 2011
Posts: 114

James, thanks tremendously for pointing me to these websites; they were very helpful. I think I understand what's going on in this code, but I'd like to ask a few questions to make sure I understand it. In the first bit of code I saw:

It looks like this is defining account to be a mock, and then in the next line the code is telling it that whenever account.passwordMatches() is called with any parameter, it should return true. Is that accurate?

Later in that same method I see:

It looks like this is an attempt to verify that setLoggedIn(), called on object account, will return true. Is that right? What does the times(1) do?

Kevin S
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

Kevin Simonson wrote:

It looks like this is an attempt to verify that setLoggedIn(), called on object account, will return true. Is that right? What does the times(1) do?

Kevin S

http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html#4
Verifying exact number of invocations - 1 time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mockito