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

The Archive Base Latest Questions

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

I like unit testing, it is proving its worth immensely for the last year

  • 0

I like unit testing, it is proving its worth immensely for the last year and a half or so ive used it. However I always have a problem or rather a niggle with private methods (and protected).

I don’t want to make them public or use internals visible to attribute. I want a clean and crisp solution – that is testable and i’d be proud to let someone else look at.

I am coming to the conclusion that if a private method really needs testing independantly then maybe it should be moved out onto another interface and use association to expose the functionality to the calling method. I believe this in essence to be the Facade pattern.

Is this really the best way to go about this?
Or more objectively … are there any other approaches I have totally overlooked?

Edit: Are we talking about a specific language?
I am working in C#. I had kept code out of the question as i was looking for something abstract. Coming back to it today i realise that is perhaps folly due to languages really being that different.

So some code:

public class CopmlexClass
{
    public void SomeMethod()
    { }

    private void workerMethod()
    { }
}

would get re factored into

public class CopmlexClass
{
    public void SomeMethod()
    { }

    public IComplexClassWorker Worker { get; set; }

}

public interface IComplexClassWorker
{
    void WorkerMethod();        
}

In fact id probably prefer to use constructor injection and not even expose the property

My question is: is that the best way? what are the alternatives bar reflection / internals visible to attribute?

  • 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-30T13:33:22+00:00Added an answer on May 30, 2026 at 1:33 pm

    A private method which needs to be tested independently can be the result of the following:

    • your class is doing too much – its public methods implement functionality which is too complex to be unit tested as a whole, and/or
    • the effects of calling the specific private method can’t be directly sensed from outside the class.

    Both cases are usually a clear call to extract another class containing some private method(s) of the original class, turned into public, thus made directly testable. (The sometimes challenging part is to find logically cohesive chunks of functionality which can form useful classes on their own right. You may not always get a perfect result at first – in refactoring, sometimes one needs to make a compromise, a small step into some not-yet-clearly-defined direction. In the long term, such a step may open up new possibilities, call attention to other similar code parts, or the new class may start to attract code bits from other places, eventually forming a coherent class. Or turning into something completely new, but better than what you originally envisioned.)

    Exposing the private method via another interface / facade is IMO not going to solve the problem in the long term, only muddles the waters. Classes should have a well defined, complete and minimal interface. Exposing private methods in any way may open up ways to compromise the internal state of the object, which is a Bad Thing.

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

Sidebar

Related Questions

I would like to do unit testing on my Sencha Touch application, I have
For the purposes of unit testing I'd like to create an iPhone project target
What are some situations where unit testing and TDD and the like are more
I am new to unit testing, and would like to know how you would
I'm new to unit testing and nUnit (2.48). I'd like to write a test
Does anyone know of where to find unit testing guidelines and recommendations? I'd like
I have been creating Unit tests like crazy and find that I'm often having
I would like to provide some custom Assert methods in my MSTest Unit Testing
I'd like to know if there are some unit testing frameworks which are capable
I'm using Python's unittest module for unit testing. I'd like to be able to

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.