permaculture playing cards
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Automatic Mocking with Spring framework" Watch "Automatic Mocking with Spring framework" New topic

Automatic Mocking with Spring framework

Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112

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
(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

Joined: May 26, 2003
Posts: 32628

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Automatic Mocking with Spring framework
It's not a secret anymore!