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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:19:19+00:00 2026-06-16T00:19:19+00:00

how can I test abstract classes and protected methods inside them? I know some

  • 0

how can I test abstract classes and protected methods inside them? I know some of you will suggest that I shouldn’t test the abstract class, but rather test the classes that derive from it instead. Thing is, I don’t want to do that. I want to strictly test the abstract class itself. Here is the sample class:

public interface IF_SystemMessageHandler
{
    ...
}

public interface IF_SystemMessageSender
{
    ...
}

    public abstract class Component : IF_SystemMessageSender
    {

        private eVtCompId mComponentId;
        private eLayer mLayerId;
        private IF_SystemMessageHandler mLogger;

        protected Component(eVtCompId inComponentId, eLayer inLayerId, IF_SystemMessageHandler inMessageHandler)
        {
            mLayerId = inLayerId;
            mComponentId = inComponentId;
            mLogger = inMessageHandler;
        }

        protected void SendSystemMessage(ref eSystemMsgLevel inSystemMsgLevel, ref string inSysMsg)
        {
            mLogger.SendSystemMessage(...);
        }

        protected void SendSystemMessage(ref eSystemMsgLevel inSystemMsgLevel, ref eTextId inSysMsgID)
        {
            mLogger.SendSystemMessage(...);
        }

        public void SetMessageHandler(ref IF_SystemMessageHandler InSystemMessageHandler)
        {
            mLogger = InSystemMessageHandler;
        }

    }

I’m writing a unit test for it. I know that one of the things I can do is utilize a unit-testing framework (I have Moq), but I have no idea on how to use it for this particular instance.

  • 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-06-16T00:19:20+00:00Added an answer on June 16, 2026 at 12:19 am

    In order for you to test your abstract class you need to instantiate it. So create a class for testing purposes that inherits from your Component (abstract) class.

    Aside from the interfaces being used I don’t see much to Mock.

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

Sidebar

Related Questions

It came to my attention lately that you can unit test abstract base classes
How can I test a private method of an abstract class using reflection (using
Let's see if I can describe this properly... I have an abstract class that
I was wondering how to unit test abstract classes, and classes that extend abstract
I know that main() can be overloaded in a class with the compiler always
I have written an abstract test case class that is to be extended by
I want to create a method in superclass of test-class that stubs some commonly
I'm trying to test some DAO Classes that inherit from a Generic one, and
I have a feature that uses the camera so I can test it only
I am writing a library that generates derived classes of abstract classes dynamically at

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.