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

  • Home
  • SEARCH
  • 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 84967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:00:54+00:00 2026-05-10T22:00:54+00:00

I have been looking at using TDD and implementing proper testing (only just started

  • 0

I have been looking at using TDD and implementing proper testing (only just started to learn how much better it makes your life) in any of my projects that I create in the future. So for the last couple of days I have been floating around on SO trying to learn about how to design your application for testability, but I still seem to be struggling with some of the ideas.

I have read a lot that you should program against interfaces rather than classes. The main problem I’m having is, how many interfaces should you create? Should you have one for everything you want to test? or am I reading this wrong?

Another thing is use lots of dependency injection, so you can mock the parts that you are injecting rather than use the real things. Is this correct? or am I way off here too?

  • 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. 2026-05-10T22:00:55+00:00Added an answer on May 10, 2026 at 10:00 pm

    I think you have the right idea, but I think you are making this into a bigger deal than it is. If you start doing TDD, your first reaction will probably be ‘is this it?’. And then later, you should hopefully say ‘aha’!

    The main thing is that you get nUnit, learn the tutorial, and then make sure you write a test for everything you do before you write the implementation. You might skip over writing tests for property accessors, but anything that requires any calculations, you should write a test first.

    So, pretend you’re testing a calculator’s Add(int 1, int 2), the first thing you think is, ‘how can I break this’. My ideas where things could go wrong are: negative numbers, zeros, and overflows. The trick is to imagine every mistake the person who is going to create the Add() method might make, and then write a test against it. So, I might write:

    Assert.AreEqual(5, calc.Add(2, 3), 'Adding positives not as expected'); Assert.AreEqual(-5, calc.Add(-2, -3), 'Adding negatives not as expected'); Assert.AreEqual(-2, calc.Add(-3, 2), 'Adding one positive and one negative not as expected');  // your framework might provide a cleaner way of doing this: try {   int result = calc.Add(Int32.Max, 5);   Assert.Fail('Expected overflow error. Received: ' + result); } catch(Exception e) {   // This should be a more specific error that I'm not looking up } 

    So, as you can see, what I’ve tried to do is figure out how the Add() method might not work, and then test against it. I’ve also looked for interesting corner cases and explicitly defined the behaviour that I’m expecting. And then now I’m free to go off and code the Add() method.

    Now, while that’s not all that great, you know that your Add() method will be rock-solid for when you start creating complex math functions that combine your Sin() method with your Sqrt() method along with your Add() method.

    That, for better or worse, is Test Driven Development. Don’t get too hung up on the interfaces or dependency injection for now. That can come later, if you need it.

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

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Ended up writing a Zend_Filter class that was basically a… May 11, 2026 at 2:36 pm
  • added an answer If a flat file is fast enough, then go with… May 11, 2026 at 2:36 pm
  • added an answer 1) Yes, at this time, ADO.net only has an implementation… May 11, 2026 at 2:36 pm

Related Questions

How would you test this scenario? I've just started looking into NHibernate and having
OK, I know there have already been questions about getting started with TDD ..
I have been looking in to doing some test driven development for one of
I am trying to move certain lines from one .txt file to another. These

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.