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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:14:58+00:00 2026-05-28T11:14:58+00:00

Since a few days ago I’ve started to feel interested in Unit Testing and

  • 0

Since a few days ago I’ve started to feel interested in Unit Testing and TDD in C# and VS2010. I’ve read blog posts, watched youtube tutorials, and plenty more stuff that explains why TDD and Unit Testing are so good for your code, and how to do it.

But the biggest problem I find is, that I don’t know what to check in my tests and what not to check.

I understand that I should check all the logical operations, problems with references and dependencies, but for example, should I create an unit test for a string formatting that’s supossed to be user-input? Or is it just wasting my time while I just can check it in the actual code?

Is there any guide to clarify this problem?

  • 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-28T11:14:58+00:00Added an answer on May 28, 2026 at 11:14 am

    In TDD every line of code must be justified by a failing test-case written before the code.

    This means that you cannot develop any code without a test-case. If you have a line of code (condition, branch, assignment, expression, constant, etc.) that can be modified or deleted without causing any test to fail, it means this line of code is useless and should be deleted (or you have a missing test to support its existence).

    That is a bit extreme, but this is how TDD works. That being said if you have a piece of code and you are wondering whether it should be tested or not, you are not doing TDD correctly. But if you have a string formatting routine or variable incrementation or whatever small piece of code out there, there must be a test case supporting it.

    UPDATE (use-case suggested by Ed.):

    Like for example, adding an object to a list and creating a test to see if it is really inside or there is a duplicate when the list shouldn’t allow them.

    Here is a counterexample, you would be surprised how hard it is to spot copy-paste errors and how common they are:

    private Set<String> inclusions = new HashSet<String>();
    private Set<String> exclusions = new HashSet<String>();
    
    public void include(String item) {
        inclusions.add(item);
    }
    
    public void exclude(String item) {
        inclusions.add(item);
    }
    

    On the other hand testing include() and exclude() methods alone is an overkill because they do not represent any use-cases by themselves. However, they are probably part of some business use-case, you should test instead.

    Obviously you shouldn’t test whether x in x = 7 is really 7 after assignment. Also testing generated getters/setters is an overkill. But it is the easiest code that often breaks. All too often due to copy&paste errors or typos (especially in dynamic languages).

    See also:

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

Sidebar

Related Questions

I've started learning rails3 few days ago, and since today, every time I run
Since a few days ago, MySQL server on my Windows machine was not successful
I few days ago I update my macbook pro to snow leopard, and since
Since it came out a few days ago, I am sure at least some
I just started with Java servlets few days ago. I am trying to develop
I’ve started learning Erlang a few days ago and it’s definitely a very interesting
I just started playing with Berkeley DB a few days ago so I'm trying
I have started to use jqGrid in our project a few days ago and
Coding on Visual C# since a few days ago. Trying to access the elements
Since the Windows 8 consumer preview was released a few days ago, I am

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.