Search the web
Sign In
New User? Sign Up
testdrivendevelopment · Test-driven Development
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Mocking concrete objects   Message List  
Reply | Forward Message #26626 of 32000 |
Re: [TDD] Mocking concrete objects

Vishal,

kumbhkaran_21 wrote:
> While doing TDD a scenario,we needed some objects which had
> data.But,since we did not want to hit the database,we created these
> objects in code,and initialized them with some values.We did not
> assign values to all the properties.Is it the right thing to do?

I think so. That describes how I use test doubles more than any other
way. I would call these "fakes" rather than "mocks" because they're
just faking data rather than checking expectations. They're no less
useful for that, though. The terminology just helps to make you
description clear when talking with other people.

> Also,can we use mock frameworks to mock concrete objects?

Some mock frameworks can work with concrete classes, and some are
restricted to interfaces. I haven't kept up with all the frameworks,
but I think you'll find plenty that can do that for you.

- George

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------




Sat Nov 24, 2007 3:03 pm

gdinwiddie
Offline Offline
Send Email Send Email

Forward
Message #26626 of 32000 |
Expand Messages Author Sort by Date

While doing TDD a scenario,we needed some objects which had data.But,since we did not want to hit the database,we created these objects in code,and initialized...
kumbhkaran_21
Offline Send Email
Nov 24, 2007
12:06 pm

Vishal, ... I think so. That describes how I use test doubles more than any other way. I would call these "fakes" rather than "mocks" because they're just...
George Dinwiddie
gdinwiddie
Offline Send Email
Nov 24, 2007
3:03 pm

In cases like yours, where you are really just trying to pass in a data object, it is simpler just to populate a real object if you can. Mocking a data object...
Corey Haines
coreyhaines
Offline Send Email
Nov 24, 2007
3:30 pm

Hello, kumbhkaran_21. On Saturday, November 24, 2007, at 7:06:10 ... Did tell you what you wanted to know? Did it permit you to go forward with more...
Ron Jeffries
ronaldejeffries
Offline Send Email
Nov 25, 2007
1:17 am

... Often no, they've been for mocking interfaces instead. Stupid languages with interfaces. ... J. B. (Joe) Rainsberger :: http://www.jbrains.ca Your guide to...
J. B. Rainsberger
nails762
Offline Send Email
Nov 25, 2007
12:38 pm

... -- Edmund Schweppe, President Firepool Consulting, Inc. - Effective Software Development (978) 621-7245 - http://www.firepoolconsulting.com...
Edmund Schweppe
ed_schweppe
Offline Send Email
Nov 26, 2007
3:06 am

... You can use JMock and its friends along with the gclib to create test doubles for concrete classes that have a public, no-argument constructor. What you...
J. B. Rainsberger
nails762
Offline Send Email
Nov 25, 2007
12:38 pm

... Sounds like it. One of our "test smells" in our Synaesthesia series is trying to mock value objects. ... Most of them will, but I don't recommend it. S ...
Steve Freeman
smg_freeman
Offline Send Email
Nov 25, 2007
2:57 pm

... "Most of them will, but I don't recommend it." Would that be a smell to look out for? Mocking a concrete class with no interface? Wouldn't it also smell if...
Rob Park
rpark68
Online Now Send Email
Nov 26, 2007
3:49 am

... I believe so. I mostly want to do it when working with legacy code, where its stench is so easily overpowered by the stenches around it. ... I don't...
J. B. Rainsberger
nails762
Offline Send Email
Nov 26, 2007
4:56 pm

... to me it would. Maybe the class should be used directly in the test. ... Not necessarily. I use interfaces more than many others to identify the roles that...
Steve Freeman
smg_freeman
Offline Send Email
Nov 26, 2007
5:18 pm

What I'm wondering about is actually when creating a new class... and it's going to be a dependency of another class... are you saying to by default give it an...
Rob Park
rpark68
Online Now Send Email
Nov 27, 2007
3:43 pm

... For me, it depends. If you know Domain-Driven Design's terms, then I never expect interfaces for Values, sometimes for Entities and always for Services....
J. B. Rainsberger
nails762
Offline Send Email
Nov 29, 2007
12:14 am

... Your rules about when to use interfaces in the domain seem sensible to me, though we don't even put interfaces on services until there is a need (and so...
Colin Jack
colin.jack
Offline Send Email
Jan 1, 2008
8:57 pm

... You don't test that your Front Controller correctly dispatches to the appropriate Service? Maybe you don't because you don't have to write code for that. ...
J. B. Rainsberger
nails762
Offline Send Email
Jan 2, 2008
1:06 am

... Sorry yeah, but we use TypeMock so we'd be testing against the concrete class. ... In my experience its common to have logic within one domain entity that...
Colin Jack
colin.jack
Offline Send Email
Jan 2, 2008
8:26 am

I realized I didn't explain why I was asking the questions. I'm interested in how you go about using mocking within the domain as a tool to help you drive...
Colin Jack
colin.jack
Offline Send Email
Jan 2, 2008
10:33 am

... Nat Pryce came up with categories for different kinds of collaborating object which helps us think about things. ...
Steve Freeman
smg_freeman
Offline Send Email
Jan 6, 2008
4:45 pm

... Which kind of logic? Pure domain logic? or service logic like persistence or participating in a transaction? The former belongs, and the latter does not. ...
J. B. Rainsberger
nails762
Offline Send Email
Jan 2, 2008
11:59 pm

... Pure domain logic, our domain model doesn't participate in transactions or persistence or anything else like that. In fact our domain layer really only...
Colin Jack
colin.jack
Offline Send Email
Jan 3, 2008
9:40 am

... What is in the first cut of MyDbClass? If it provides some kind of external service that finds things for me (described in the domain of the application),...
Steve Freeman
smg_freeman
Offline Send Email
Nov 29, 2007
12:56 pm

Let's say it's just a simple UserDaoAdo.cs class, because I need a FindUser(). I'm just wondering if you'd create the UserDao interface (kind of by default)...
Rob Park
rpark68
Online Now Send Email
Nov 29, 2007
7:43 pm

Hi all, I'm playing with Rhino Mocks and have some questions 1. When I call on my mocked view: Expect.Call(_viewMock.FirstName).Return("damien"); What's...
Damien Lynch
dlynch123321
Offline Send Email
Nov 30, 2007
1:21 am

You need to distinguish between constraints, which check how an object is called, and actions, which return a value or throw an exception to support the rest...
Steve Freeman
smg_freeman
Offline Send Email
Nov 30, 2007
2:54 pm

My colleague Nat has a horror of classes called *Repository, *Dao, etc. because that sort of name is about implementation not the domain. In this case, an...
Steve Freeman
smg_freeman
Offline Send Email
Nov 30, 2007
3:00 pm

Hi Vishal, Please take a look at the following post that explains a similar problem to what you are experiencing, and Mocking technique I use when dealing with...
ndibek
Offline Send Email
Nov 26, 2007
7:16 pm

With an interface. Sent from my iPhone ... Your rules about when to use interfaces in the domain seem sensible to me, though we don't even put interfaces on...
Brian Leahy
brianleahy76
Online Now Send Email
Jan 2, 2008
5:39 am

... You should never mock a value object. Or need to, for that matter. --Nat...
Nat Pryce
nat_pryce
Offline Send Email
Jan 26, 2008
8:56 am

... entities/value ... Ta for replying and I agree. I actually follow basically the testing approach described in the article for entities too, rarely mocking ...
Colin Jack
colin.jack
Offline Send Email
Jan 26, 2008
9:54 am

... A system comprises many domains. E.g. domains of business logic, communication, persistence, etc. Classes in any domain either represent values or objects...
Nat Pryce
nat_pryce
Offline Send Email
Jan 26, 2008
10:38 pm
First  | < Prev  |  Last 
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help