RE: Best approach to TDD - advice needed

"Donaldson, John (GEO)" <[email protected]> Thu, 22 Sep 2011 16:52:30 +0100
Newsgroups gmane.comp.programming.refactoring
Message-ID <8A89F8BA0CF8D14BB5E18AEEBBAC36EF72494D9E3F@GVW1121EXC.americas.hpqcorp.net>
Rakesh,

Here is what I would do. (You are practicing TDD aren't you?)

1. Write a service-level test to your service which will get no data. You can make that pass easily with a static return.
2. Write a service-level test to your service which should get some data - it will fail. You may be able to make it pass easily by returning some static, hard-coded data. If not it's not easy to get it to pass comment it out and go to 4 directly.
3. Write a high-level test which will be difficult to make pass with static data - it will need to do whatever you do to get the real data. Comment out this failing test so your tests are all green.
4. Refactor the service so that your service implementation delegates directly to a Plain Old Java Method on a POJO. I don't think I would mock at this point, but you certainly could.
5. Write a bunch of tests to drive the implementation of the POJO.
6. Uncomment your failing service test, which should now pass.

John D.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Rakesh
Sent: 22 September 2011 12:28
To: [email protected]
Subject: [refactoring] Best approach to TDD - advice needed

Hi,

I am developing some service that return a List of products. The service
will get the data from a REST interface.

My question is should I just start writing the service method with all the
low level JSON code in the method. Once the test passes, start pulling out
functionality into their own classes, changing the earlier service unit test
to a mocking style test?

Or should I try and write the service test with the dependencies I think it
needs and once thats working, move onto the other classes?

Does that make sense?

Thanks

Rakesh


[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links





------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/refactoring/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/refactoring/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/