Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5943115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:20:57+00:00 2026-05-22T16:20:57+00:00

I have a recipe method which i am trying to write using TDD. It

  • 0

I have a “recipe” method which i am trying to write using TDD. It basically calls out to different methods and occasionally makes decisions based on results of these methods:

  public void HandleNewData(Data data)
  {
     var existingDataStore = dataProvider.Find(data.ID);
     if (data == null)
        return;

     UpdateDataStore(existingDataStore, data, CurrentDateTime);

     NotifyReceivedData(data);

     if (!dataValidator.Validate(data))
        return;

     //... more operations similar to above
  }

My knee jerk reaction would be to start writing test cases where I verify that HandleNewData calls the methods seen above passing the expected arguments and that it returns in those cases where the method call fails.
But this feels to me kind of like this is a huge investment in time to code such a test up with little to no actual benefit.

So what is the real benefit of writing such a test? Or is it really not worth the bother?

It seems like it is just an over-specification of code it self, and will lead to maintenance problems whenever that code has to call another method or decide to not call one of the current methods anymore.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:20:57+00:00Added an answer on May 22, 2026 at 4:20 pm

    TDD does not mean writing unit tests for code that already exists (although sometimes it may be necessary when improving legacy code).

    You’ve probably heard the term “Red, Green, Refactor”. This is the approach we take when doing TDD. Here are the three laws of Test-Driven Development, which take that a little further…

    1. You may not write production code
      until you have written a failing
      unit test.
    2. You may not write more of a unit test than is sufficient to fail, and
      not compiling is failing.
    3. You may not write more production code than is sufficient to pass the
      currently failing test.

    The benefits of taking this approach is that you end up with very close to 100% unit-test coverage and you know that your code works exactly as specified.

    It will reduce maintenance problems because as soon as somebody makes a change to your code and runs the tests, they will know if they have broken anything.

    In this case, I would incrementally add unit tests for the methods being called from HandleNewData() before adding any for HandleNewData().

    Adding unit tests to legacy code is tough, but doable and very much worth the effort. If you haven’t yet, I really recommend reading Working Effectively with Legacy Code by Michael Feathers. I’ve found it invaluable when adding unit tests to a 25-year-old code-base.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base recipe class and I am using a datacontext. I overrode
I have a capistrano deployment recipe I've been using for some time to deploy
I have some old rrdtool databases, for which the exact creation recipe has long
Basically I have a proof-of-concept application that is a digital recipe book. Each Recipe
I have a user model in which I have a method for seeing if
I have two models, Article and Recipe, which have a bunch of the same
Let's pretend I have a large recipe-database. A table for recipes each with an
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
I have this markup in an MVC app. <div id=ingredientlistdiv> <% Recipe recipe =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.