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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:42:08+00:00 2026-05-17T19:42:08+00:00

I am new to TDD and DDD and I have one simple question regarding

  • 0

I am new to TDD and DDD and I have one simple question regarding static methods in general. Most of the gurus of TDD says in one word that static methods are bad (and that we should forget about creating tons of static utilities that we (um or I) used to make before as they are not testable. I can see why they are not testable ( a great clarification article can be found here for those who are interested but I guess I am the only noob here 🙁 ) but I was wondering is there a nice and clean guideline for using statics from TDD point of view?

This may be really silly question for most of you but some tips would be great and I just want to know how experts here think of static stuff. Thanks in advance.

Edit: While looking for answer I found 2 other nice threads regarding usage of static ( not TDD concern though) which I guess are good reads for those who are interested(myself inclusive).

  • Topic 1
  • Topic 2
  • 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-17T19:42:08+00:00Added an answer on May 17, 2026 at 7:42 pm

    I think you may have slightly misunderstood.

    Static methods are testable. Take this method as an example:

    public static int Add(int x, int y)
    {
        return x + y;
    }
    

    You can test this by testing that the return value is what you expect based on the arguments passed in.

    Where static methods become troublesome when testing is when you need to introduce a mock.

    Let’s say I have some code that calls the File.Delete() static method. To test my code without relying on the file system, I would want to replace/mock this call with a test version that just verifies that it has been called from the code being tested. This is easy to do if I had an instance of an object on which Delete() was being called. Most (all?) mocking frameworks can not mock static methods, so using a static method in my code forces me to test it differently (usually by calling the real static method).

    To test something like this, I would introduce an interface:

    interface IFileDeleter
    {
        void Delete(string file);
    }
    

    My code would then take an instance of an object that implements this interface (either in the method call or as a parameter in the constructor), and then call its Delete() method to do the delete:

    void MyMethod(string file)
    {
        // do whatever...
        deleter.Delete(file);
    }
    

    To test this, I can make a mock of the IFileDeleter interface and simply verify that its Delete() method had been called. This removes the need to have a real file system as part of the test.

    This may look like the code is more complex (which it is), but it pays for itself in making it far easier to test.

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

Sidebar

Related Questions

I'm very new to TDD world. I have a few questions regarding TDD. Do
Im new at TDD and i still have many questions, and one of this
So I'm trying out this new TDD thing (about time haha). Anyways I have
I am new to unit testing and TDD and mocking in general, however the
I am quite new to TDD and the first question which came into my
I'm pretty new to TDD. I see some docs says about positive test, negative
I am sort of new to TDD. I have started creating the properties I
I'm very new to TDD and I'm having trouble with one of my unit
I am fairly new to TDD but have been using it for long enough
I am relatively new to using TDD and have been reading about mocking objects

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.