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 7160393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:23:30+00:00 2026-05-28T13:23:30+00:00

I am learning TDD and I currently have a method that is working but

  • 0

I am learning TDD and I currently have a method that is working but I thought I’d have a go at rebuilding it using TDD.

The method essentially takes 6 parameters, queries a database, does some logic and returns a List<T>

My initial tests including checking for empty/zero defined string and int method parameter values but now I’m not sure what to do. If I wasn’t using TDD, I would just create code to find the DB connection string and open up a DB connection, query the database, read the values etc.

Obviously we can’t do that in Unit Testing so I was after some advice of how to proceed.

  • 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-28T13:23:31+00:00Added an answer on May 28, 2026 at 1:23 pm

    Remember that TDD is as much about good design than it is about testing. This method has too much going on; it violates the Separation of Concerns principle.

    You’ve already identified several areas that will need to be tested:

    The method essentially takes 6 parameters, queries a database, does some logic and returns a List<T>

    You have several discrete steps there, and there are probably a few more hiding in the code. Breaking those up is the name of the game when it comes to TDD.

    For starters, it might be a good idea to factor out the piece that performs the logic.

    Is your method building a query dynamically? Break that piece out as well and test it to make sure the query is written properly.

    You can put the execution of the query into a standalone repository or something similar, and write integration tests against that. That way you only have a simple test hitting the database instead of the current complex method.

    If you try to test this as is, you’ll likely end up with a monster test that requires a lot of setup and duplicates all of your business logic, and when it breaks it’ll be unclear as to what went wrong.

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

Sidebar

Related Questions

I have been learning about TDD (using JUnit) and I have a doubt about
I'm working on learning TDD while writing some small ruby programs. I have the
I'm learning TDD, and I have a question about private / protected variables. My
Learning jquery, so please be kind :) Using PHP, I have a table with
I am learning TDD and using CppUTest in eclipse. Is there any way to
I've been learning what TDD is, and one question that comes to mind is
learning Jquery and integrating with PHP - getting there, but have one last challenge
I'm creating a graph framework for learning purposes. I'm using a TDD approach, so
Learning Objective-C and reading sample code, I notice that objects are usually created using
I'm learning to do TDD in practice in small project. I want to create

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.