This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Testing and the fly likes replayAll() & verifyAll() in PowerMock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "replayAll() & verifyAll() in PowerMock" Watch "replayAll() & verifyAll() in PowerMock" New topic

replayAll() & verifyAll() in PowerMock

vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 151


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().

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

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:
call runDatabaseScript()
run code under test that calls runDatabaseScript()
yes. the code works as intended

Now consider another scenario:
Pseudo code:
call runDatabaseScript()
run code under test that is blank/doesn't do anything
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()

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: replayAll() & verifyAll() in PowerMock
It's not a secret anymore!