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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:25:38+00:00 2026-05-27T18:25:38+00:00

I understand that @VisibleForTesting is not desirable because it changes the interface of a

  • 0

I understand that @VisibleForTesting is not desirable because it changes the interface of a class just for testing purposes. Ideally we should test the interface that we actually use. But what would be a good alternative?

  • 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-27T18:25:39+00:00Added an answer on May 27, 2026 at 6:25 pm

    You use @VisibleForTesting when, as you said, you want to test a part of code you’re not exposing to the end user. If you want to test it then it most likely means it’s complicated, or at least not trivial. Two solutions would be:

    1. Split the method where you’re calling this into several methods so you feel more comfortable about not having one big method doing a bunch of stuff at once.
    2. See if you can move the behavior to an external object that takes care of it.

    I like #2 a lot when stuff starts getting complicated, since I can have an external object that I can test and make sure it works without having to expose it through our interface.

    Having said that, some times the behaviors don’t warrant the extraction of the method into a new object and you use @VisibleForTesting just to save time. Experience is what tells you when it’s worth it to do it (or not).

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

Sidebar

Related Questions

I understand that IronPython is an implementation of Python on the .NET platform just
I understand that this response clearly states that this is not possible without a
I understand that loops are a bad idea in python and I should avoid
I understand that a class will have a VTABLE , if it contains at-least
I understand that the List<> of derived class cannot be directly assigned to List<>
I understand that only the class can access the data so therefore it is
I understand that git diff compares a staged file and modified but not staged
I understand that if you /// above a class, field, method, or property Visual
Understand that 1x1 widget size should be 72 dip x 72 dip, but this
I understand that if else staments should say stuff like: if dog equals one,

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.