• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mockito

 
Kevin Simonson
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic