Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

replayAll() & verifyAll() in PowerMock

 
vivek dhiman
Ranch Hand
Posts: 152
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can someone explain replayAll() and VerifyAll() in details with some example. As replayAll() is still bit clear but not able to understand what verifyAll() exactly does. I have some test cases that runs successfully even i don't use verifyAll(). Can someone provide the sample code snippet which describe importance of verifyAll().

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek,
I haven't used PowerMock, but I have used other mock libraries with the same concepts.

A mock starts out in record mode where you say what is going to happen. You then switch to replay mode and run the real code. At the end you call verify to confirm what you actually said was going to happen did in fact happen.

Pseudo code:
record:
call runDatabaseScript()
replay:
run code under test that calls runDatabaseScript()
verify:
yes. the code works as intended

Now consider another scenario:
Pseudo code:
record:
call runDatabaseScript()
replay:
run code under test that is blank/doesn't do anything
verify:
fail - we never called runDatabaseScript()

The problem is when you don't call verify. The second scenario doesn't fail because verify isn't called to know you never called runDatabaseScript()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic