aspose file tools*
The moose likes Spring and the fly likes Automatic Mocking with Spring framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Automatic Mocking with Spring framework" Watch "Automatic Mocking with Spring framework" New topic
Author

Automatic Mocking with Spring framework

Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
Hi,

I am suppose to write unit testing code for my BO (business) layer by mocking DAO layer. I am using Java 1.4 and Spring 2.5 combination and need to strictly use this combination only.

I have tried to use the JMock API for this and i could inject the Mock DAO objects into the Business objects manually.

But i thought that it is a dirty way to inject mock objects. The difficult thing i could face using JMock is in setting up the mock data and injecting the mock objects manually.

As i am already using Spring framework for my application, i thought of making use of Spring for unit testing and automatically injecting DAO mock objects into BO objects while unit-testing.

Is there a way to define mock objects, setting expectations for mock objects, maintaining test
data
(kind of binding) using spring specifically using Spring configuration files. (in a configurable way)

Hope i am clear on my requirement. Thanks in advance for your time and attention.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30925
    
158

What are you hoping Spring will do for you? You still need to specify the expectations manually whatever you do.

For integration tests, Spring adds value. For unit testing, I don't see how it is easier to involve Spring.


[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
 
 
subject: Automatic Mocking with Spring framework