Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Objects for testing Web application

 
ken connor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to use Mock Objects (www.mockobject.com) to mock test
my web applications? It seems very handy. Only problem is that it's a little
bit difficult to an practical overview how to actually do it...
Can anyone clearify me or can anyone point me any tutorials?
Best Regards
Ken
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I started out with MockObjects by reading DevelopingJdbcApplicationsTestFirst and then browsing the MockObjects API to see what other built-in mock objects they've got.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ken connor:
I would like to use Mock Objects (www.mockobject.com) to mock test
my web applications? It seems very handy.

Handy in which ways?
In my humble opinion, mock objects are rather deep in the bag of tricks - you should use them sparingly...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34371
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ilja, I disagree. I think creating your own mock objects should be done sparingly. But using ones that are already provided can be fast and useful. For example when using Struts, you can use a MockHttpServletRequest, MockHttpServletResponse and MockHttpSession.. Then you can develop a lot of code without the server. This is very helpful in unit testing the methods and making sure everything gets set in the session correctly.
 
ken connor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thing these MockObjects are cool way to do unit testing especially
in server-side. You don't need containers, but ok someone else might ignore this.
Actually, most I would like get some kind of picture what the process
is when you use www.mockobjects.com's different products for unit testing.
There is Mockrunner, EasyMock, MockEJB, MockCreator. If I leave Ejbs out of testing first MockEJB is not needed. But how about these three other 'products'... are there a suggested way (or process) to use these three products if I like to e.g. test servlets? Like to know more about
the whole picture of this MockObject testing process...
Anyone used all of this products in unit testing?
- ken
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
But using ones that are already provided can be fast and useful.

In my experience they often still are more complex to use than I'd like testing to be.
For example when using Struts, you can use a MockHttpServletRequest, MockHttpServletResponse and MockHttpSession.

I agree that for testing servlet-specific code, mocks or dummies can be very helpfull. My point would be, though, that typically your servlet layer should be *very* thin and contain as few logic (and therefore tests) as possible. The vast amount of your tests shouldn't have to do with servlets at all.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34371
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The vast amount of your tests shouldn't have to do with servlets at all.

That I agree with!
 
ken connor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeps, it's quite typical that when you ask something from forums considering HOW to do or what is the best practise way to use software/technique or where to get more information of it, people are answering their opinions considering the software or technique.
It's like politics... the actual question was more like technicall
not 'political option' what is good or bad...
But okey, I try another forum again.
 
ken connor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe there should new opinion groups in Javaranch:
My Servlet opinions
My JSP opinions
My.....
etc.
Those remaining forums could have more like technical perspective
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ken, it's also quite common that people ask questions regarding specific techniques when in fact they are trying to solve a more general problem. It is my experience that it helps a lot to know about that problem to both answer the technical question in a more focused way and even propose alternative solutions the original poster possibly wasn't aware of. Perhaps I could have phrased my post in more constructive way, and I apologize for not doing so.
Personally, I find that discussions about "technical opinions" are probably the most valuable in a forum. If you don't agree, I don't think that should be a problem - different styles should be able to coexist at the Ranch. I'd just ask you to accept that I actually wanted to help you, and to remember our "be nice" rule, if you decide to stay anyhow. I, on the other hand, will try to remember to only give direct answers to your questions in the future.
No hard feelings, Ilja
[ September 17, 2003: Message edited by: Ilja Preuss ]
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ken, I appreciate your willingness to use sarcasm, but encourage you to be open to "non-technical" opinions. As this is a friendly place for greenhorns, we often find people asking questions about how to do something that may not be approproiate for their needs. I'm not saying that this was the case with you merely that others might come across this thread and get excited about using mock objects even if they shouldn't be. Ilja was just posting a warning sign.
More generally, as an engineer I'm sure you've come to appreciate that there is no one right way to do things. Different approaches work best depending on the particulars of the situation. Ilja was discussing the subtleties which underly the question of which technology to apply and in what way. I've always found his insights useful, even when I disagree with them.
--Mark
 
ken connor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an Master of Science (Software Engineering) my point is to find technical solutions to problems not opinions without any explanations.
I thing our customers want good service. It contains ability to talk with
them about their needs in Software business and a strong technical knowledge of software engineering. If you don't understand this it's impossible to work as an consultant.
Of course if someone (in this case I) say back something to your 'bartender'
friend you will defend his talks Your friend should learn yo take back talks especially if he starts to 'nack' with someone first
See you!
[ September 26, 2003: Message edited by: ken connor ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ken, I really have some problems following you.
From your posts I understand that the problem you want to solve is unit testing web applications. You somehow think that mockobjects would help.
I am sorry that I can't tell you about a tutorial or the like - I don't know one. Now that I think about it, though, you might want to take a look at "JUnit in Action" by Vincent Massol - it has some good chapters on the subject. (I happen to be one of the proofreaders.) ("Extreme Programming for Web projects" might also contain some hints, as XP has a very strong focus on unit testing.)
So I can only speak from personal experience. As already stated, I seldom use mock objects, as I find them to be rather complex. I think that most parts of a web applications are more effectively tested without the use of mock objects.
To tell you more, I'd need to know more about the problem(s) you try to solve. That's why I asked what you find to be handy about mock objects. Preferably you could answer with a more specific problem you'd think they would solve, so we could than explore how you could use them and perhaps even what alternatives exist, if you'd care.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic