*
The moose likes Testing and the fly likes Help: problem with EasyMock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Help: problem with EasyMock" Watch "Help: problem with EasyMock" New topic
Author

Help: problem with EasyMock

Daniel D. Guo
Ranch Hand

Joined: Jun 07, 2004
Posts: 30
Hello,

I tried to learn a mocking framework for testing with JUnit. EasyMock seems to be a good one, but I keep having problems with it. I am attaching the code as follows:









Basically, verify in tearDown cannot catch that stream.close() not being called, while it is supposed to be because "stream.close()" is specified before replay(stream) in testGetContentOk. Any idea is greatly appreciated.

Thanks a lot!

Daniel
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Daniel,
I've moved on to jMock, but aren't you supposed to call stream.close() from within an expect method like you do for the read methods?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Daniel D. Guo
Ranch Hand

Joined: Jun 07, 2004
Posts: 30
Jeanne,

Thanks for your post!

Actually, I was trying to create an error by not calling close.

May I ask why you switched to JMock?

Thanks,
Daniel
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

I used EasyMock pre-Java 5. Some collegues used jMock which was more powerful, but I didn't want my project to be using 2 mock frameworks and people have to switch back and forth. I did use jMock on JavaRanch proejcts and liked it better. It was easier to control and more powerful.

When we migrated to Java 5, there was an opportunity to change to something different. (easyMock and jMock both changed a lot with Java 5.) I took that as an opportunity to switch to jMock. EasyMock is a lot better now, but I still like the matchers in jMock more.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help: problem with EasyMock