aspose file tools*
The moose likes Testing and the fly likes Mock Objects for testing Web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Mock Objects for testing Web application" Watch "Mock Objects for testing Web application" New topic
Author

Mock Objects for testing Web application

ken connor
Greenhorn

Joined: Sep 15, 2003
Posts: 5
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30938
    
158

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.


[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
ken connor
Greenhorn

Joined: Sep 15, 2003
Posts: 5
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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: May 26, 2003
Posts: 30938
    
158

The vast amount of your tests shouldn't have to do with servlets at all.

That I agree with!
ken connor
Greenhorn

Joined: Sep 15, 2003
Posts: 5
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

Joined: Sep 15, 2003
Posts: 5
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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Dec 04, 2000
Posts: 6037
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

Joined: Sep 15, 2003
Posts: 5
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

Joined: Jul 11, 2001
Posts: 14112
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock Objects for testing Web application