• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JUnit Recipe's - Q 4 Author  RSS feed

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw you cover something called EasyMock.
I've used JUnit but not that.
Is that the best way to create Mock objects?

Is it easy to create Mock objects without that extension?

Do you talk about when is the best time to use Mock Objects for testing?

Do you also cover how to include your JUnit tests in a build file - or is that more geared to the JUnit in Action book?

There's a very subtle problem if you use JUnit and Ant. Erik Hatcher explained what I was doing wrong but I wouldn't see source code on failed assertions because Ant tasks for compiling have debug turned off by default. You have to turn the debug back on to show source code.

Do you have any tidbits like this in your book?

Do you suggest how much is too much for creating Unit Tests - or is this another JUnit in Action item instead?

Are there examples of how to use the HTMLUnit?
Is that the same as HTTPUNIT?
 
author
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I saw you cover something called EasyMock.
I've used JUnit but not that.
Is that the best way to create Mock objects?



I'm not prepared to say "the best". At the time, it was the tool I liked most. These days, I prefer jMock, but EasyMock is certainly quite good.

Is it easy to create Mock objects without that extension?



This depends on your goal. I use EasyMock a lot in the book to implement "fake" objects--ones that just return hardcoded data--and sometimes it's easier to do that with anonymous subclasses/implementations.

If, however, you're using true mock objects--ones that record how they were used, then compare that to your expectations--then dynamic mock objects (EasyMock, jMock) are almost always easier than static mock objects (like the Mock Objects project).

If it helps, many of the people who worked on Mock Objects are now working on jMock/nMock.

Do you talk about when is the best time to use Mock Objects for testing?



I use Mock Objects whenever they are required, and I include an essay that talks in general about the different kinds of mock objects.

Do you also cover how to include your JUnit tests in a build file - or is that more geared to the JUnit in Action book?



Scott Stirling includes a lot of good information on Ant integration and I added a little. Chapters 3, 5, 6, 7 all talk about Ant extensively.

There's a very subtle problem if you use JUnit and Ant. Erik Hatcher explained what I was doing wrong but I wouldn't see source code on failed assertions because Ant tasks for compiling have debug turned off by default. You have to turn the debug back on to show source code.

Do you have any tidbits like this in your book?



Well, certainly not that one, but we have included stories from past experience, including those kinds of little problems that we had to fix the hard way.

Do you suggest how much is too much for creating Unit Tests - or is this another JUnit in Action item instead?



I do write about when not to write tests for things like constructors, get/set methods, and so on. There is an essay entitled "Too simple to break".

Are there examples of how to use the HTMLUnit?
Is that the same as HTTPUNIT?



I use HtmlUnit extensively in Part 2, both testing web UIs in isolation and for testing applications from end to end. HtmlUnit is quite similar to HttpUnit.

Thanks for all your great questions! I hope you enjoy the book.
 
Greg Ostravich
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the well thought out replies!
They're terrific and helped me understand Mock objects a little better.

Greg
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!