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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:10:14+00:00 2026-05-29T10:10:14+00:00

I am wondering if unit testing private methods is a good practice? Normally only

  • 0

I am wondering if unit testing private methods is a good practice?

Normally only public interface should be tested.

However, I have found out that during complex calculation, which calls tons of different private methods, it is easier to unit test the private methods first, and then make a simple test for the public interface method.

As an example let’s say you have an audio player and you have functions:

void play(){ ... }
void pause(){ ... }
void seek(time t)
{
    //All Private methods
    checkIfValidTimeRange(...);
    moveToFilePos(...);    
    fillBuffers(...);      
}

Normally I would write unit tests for : checkIfValidTimeRange(...), moveToFilePos(...), fillBuffers(...).

But I am not sure if doing so is good practice.

  • 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-29T10:10:14+00:00Added an answer on May 29, 2026 at 10:10 am

    It’s not a good practice (yet that doesn’t mean you should never do that), and if possible you want to avoid it. Testing private method usually means your design could be better. Let’s take a quick look at your player example:

    • moveToFilePos: sounds more like a responsibility of something doing I\O operations, not a music player’s
    • fillBuffers: more of a memory manager’s job rather than music player
    • checkIfValidTimeRange: again, probably could be moved out of player’s scope to some simple validation class (seems like this one might be useful in other places aswell)

    At the moment your music player does I/O, memory management and what not else. Is that all really in scope of its responsibilities?

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

Sidebar

Related Questions

I'm wondering how I should be testing this sort of functionality via NUnit. Public
I have heard the term unit testing many times and I am wondering how
I have a package private implementation of an Interface, the methods defined in that
I am wondering what people have found their best practice to be for testing
I've read a little bit about unit testing and was wondering how YOU unit
I'm wondering how the few Delphi Programming users here are doing unit testing, if
I think I understand unit testing. But I was wondering: is there a way
I was wondering if anyone here has experience in unit testing LOB applications (typically
I'm trying to get started with unit testing in Python and I was wondering
I am wondering should I write unit test for everything. There are some classes

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.