Search the web
Sign In
New User? Sign Up
domaindrivendesign · Domain-Driven Design
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

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
Testing The Domain   Message List  
Reply | Forward Message #5685 of 16690 |
Re: [domaindrivendesign] Testing The Domain

David makes some interesting points.

As I said a moment ago, I like to avoid factory methods in the text
fixture. But I'd be open minded if the project had well-defined
aggregates and the factory method was creating one, to be tested as a
whole. (Of course, that factory behavior might also be useful to the
app, so perhaps it could be the basis of a separate factory).
Unfortunately, what I more often see with those factory methods in tests
is that they are compensating for the lack of clear aggregate boundaries.

Also a good point about domain services tending to have legitimate
dependencies, hence mocking them makes sense in many tests. For example,
in timeandmoney, the "TimeSource" interface enables this approach. Most
real TimeSource implementations are coupled to something external to the
program (the system clock, an Internet time service) and you don't want
that intruding on your tests. To test application logic that uses a
TimeSource, you need a dummy of some kind that returns a known value and
doesn't make the test dependent on some external resource (even though
the live program will be).

Interesting description of testing the factories by giving them mocks to
assemble. (If I understood.) The upside of that would be to discourage
the factory from becoming more than a factory.

They are necessary some times, and can be used well, but I still see
mocks more often covering up model/design problems.

Eric

P.S. By the way, I prefer not to put factory methods in the repository.
Seems to blur its responsibility of being the access point for obtaining
preexisting objects. Factories make new objects.



David Laribee wrote:
>
>
>
> I treat the Aggregate as a unit. It's simply inelegant, IMHO, to
> create seams for collections, etc. I generally state test my
> Aggregates. You'll end up with a fixture-per-aggregate. A couple of
> strategically placed Factory Method inside your test fixture ( e.g.
> GetCustomerForThisScenario()) will do wonders for your sanity / test
> lengths. I tend to use what I call Testable Mask when things get hard
> to verify. That is, protected fields in the entity/aggregate that you
> can expose via a subclass where you perform the test.
>
> I treat Domain Services as a unit and test them in a mock style. I try
> to keep my tests down to one mock object and however many stubs
> (sometimes domain services have a number of dependencies).
>
> .
> _,___



Sun Jul 22, 2007 8:34 pm

ericevans0
Offline Offline
Send Email Send Email

Forward
Message #5685 of 16690 |
Expand Messages Author Sort by Date

Hi, We're looking at how we test within our project and there has been a lot of discussion about which approach to prefer when setting up the environment for...
colin.jack
Offline Send Email
Jul 22, 2007
7:27 pm

Colin, In reference to the first choice you layed out, I have a definite preference. ... I prefer real instances. Consider the things that often stop people...
Eric Evans
ericevans0
Offline Send Email
Jul 22, 2007
8:04 pm

Hi, Thanks for the superb reply, really gives weight to our approach and its great to get such a well thought out reply. On the factory front I think I...
colin.jack
Offline Send Email
Jul 23, 2007
6:50 am

Hi Eric, I've been thinking more about what you have said about the need to have test object factories and I want to pick your brain a bit a bit more on it. ...
colin.jack
Offline Send Email
Jul 24, 2007
7:14 pm

The whole test factory approach resembles the ObjectMother test pattern where you create test factories whose sole purpose is to create test objects and to...
carel.lotz
Offline Send Email
Jul 25, 2007
12:50 pm

The test factory approach sort of resembles the ObjectMother pattern where you create test factories whose sole purpose is to create test objects and to tailor...
carel.lotz
Offline Send Email
Jul 25, 2007
12:51 pm

To me it comes down to how you define the unit. (I also recognize some people are nuts about interfaces and mocking, but... to each their own.) I treat the...
David Laribee
davidlaribee
Offline Send Email
Jul 22, 2007
8:08 pm

David makes some interesting points. As I said a moment ago, I like to avoid factory methods in the text fixture. But I'd be open minded if the project had...
Eric Evans
ericevans0
Offline Send Email
Jul 22, 2007
8:34 pm

Great post thanks, you are definitely right that after the design stabilizes the tests being coupled to the implementation isn't a problem but up till that...
colin.jack
Offline Send Email
Jul 30, 2007
9:07 pm

You are quite right, what we're doing is very similiar to ObjectMother and your post was very interesting, I've posted a few questions in comments on it. I...
colin.jack
Offline Send Email
Jul 30, 2007
8:55 pm
Advanced

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