Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Automatic Mocking with Spring framework

 
Venkata Sirish
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic