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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:24:48+00:00 2026-05-24T01:24:48+00:00

I want to test the following logic (this is obviously a stripped-down version of

  • 0

I want to test the following logic (this is obviously a stripped-down version of my method):

public void myPublicMethod(params) {

    if(some_condition)
        privateMethod1();
    else
        privateMethod2();
} 

I have all of the other dependencies in the method mocked out, and I’ve set this up so that I can guarantee that some_condition is true. What I want to do is verify that my privateMethod1() is called exactly once, and privateMethod2() is not called at all. Is this possible to do with Moq?

Here are some notes on the issue:

  • privateMethod1() and privateMethod2() are within the same class as myPublicMethod, so I can’t create a mock object for this class.
  • The bodies of privateMethod1/2 both contain many, many dependencies from the class that contains these and myPublicMethod, so breaking out privateMethod1/2 into their own helper class would be prohibitively time-consuming

Any thoughts? Thanks in advance. I’m willing to accept that this can’t be done, but I’d like to know one way or another.

  • 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-24T01:24:49+00:00Added an answer on May 24, 2026 at 1:24 am

    Don’t test private methods. They are private implementation details of the class. You should only test the results of executing public methods. As long as your results come out as expected, you shouldn’t care how the result is obtained.

    Building tests on private methods will lead to brittle tests that break easily when you refactor private implementations (for performance or other reasons).

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

Sidebar

Related Questions

i want the following functionality. input : this is test <b> bold text </b>
I have the following XML <title> This is a <highlight>test</highlight> thanks. </title> and want
The method I want to test has a for loop with logic for each
I want to test whether an object is empty: {} . The following is
I want to enforce on my code base immutable rule with following test [TestFixture]
How I'm stuck with writing a test for the following code. I want to
I've set up the following for loop to accept 5 test scores. I want
We want test the JTAPI feature of our application. Are there any emulator for
I want test a FIX gateway for our company and was wondering if anything
i want to test app from xcode on real device. i have development certificate

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.