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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:10:59+00:00 2026-05-13T20:10:59+00:00

In our Core domain model design, we have got a class called Category whose

  • 0

In our Core domain model design, we have got a class called “Category” whose constructor is internal by design. Since the constructor is internal, when writing unit test cases I won’t be able to create the object of “Category”.

So my question, is it a best practice to make the constructor public just for making the “Category” class testable? Or I shouldn’t be testing that “Category”, instead I should have tested the Class/method responsible for creating this object?

Ta,

Rajeesh

  • 1 1 Answer
  • 2 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-13T20:10:59+00:00Added an answer on May 13, 2026 at 8:10 pm

    TDD means Test-Driven Design, and a corrolary to this is that a constructor can’t really be internal “by design” if you can’t test it.

    Consider why it’s internal. This will tell you how to address the issue. You shouldn’t make the constructor public just to be able to test it, but you should consider a design that makes it easy to create new instances.

    Often, constructors are made internal to protect invariants, but you could just as well achieve the same goal with a public constructor that takes required input as constructor parameters.

    public class MyClass
    {
        private readonly string requiredString;
    
        public MyClass(string requiredString)
        {
            if (requiredString == null)
            {
                throw new ArgumentNullException("requiredString");
            }
            this.requiredString = requiredString;
        }
    }
    

    Notice how the combination of the Guard Clause and the readonly keyword protects the invariant of the class. This is often a good alternative to internal constructors.

    Another reason for having internal constructors is when you have a Factory Method that may return a polymorphic object, but once again, consider if it would be a problem to expose the constructor if it doesn’t mean compromising invariants.

    The beauty of TDD is that it forces us to take a good look at any design decision and be able to really justify each and every one of them. Consider the justification of making the constructor internal and then modfiy the API so that the type is easy to create.

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

Sidebar

Related Questions

Our core domain so far has an abstraction called PersonName with methods for firstName,
Sup! We have core class with mysql connection, than we include plugin and we
We would like to publish a base model, that represents our core business data.
In our CORE library we offer this class as a 20,000 line abstraction. Can
Let me set up my LOB scenario. I am re-writing our core business app.
We are currently rewritting the core of our services, basically we have scheduled tasks
We have a custom object in Salesforce called domain which reflects each website we
We have a 12-year-old Ms Access app that we use for our core inventory
We have the following scenario with our project: A core web application packaged as
We're investigating the cloud for a couple of solutions and for our core product.

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.