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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:29:09+00:00 2026-05-26T08:29:09+00:00

How do I mock non-overridden non virtual/virtual methods in a base class and test

  • 0

How do I mock non-overridden non virtual/virtual methods in a base class and test just the derived class’s methods?
The case here is:
I have a base class X which has methods that connect to an external server and do a couple of other things.
I have a class Y derived from X. I have implemented two methods in Y. I want to just unit test them. I am worried only about these two methods and I don’t want the base class implementation to be called to connect to the server etc( I want to mock those methods out , but i don’t want to override those methods in my derived class Y and do nothing in them, since it is production code).
Any thoughts /ideas on how can I unit test my those methods in isolation?

P.S: I am using C++/GTest for development and unit testing.

  • 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-26T08:29:09+00:00Added an answer on May 26, 2026 at 8:29 am

    One option is to create a Mock_base class and the class Derived inheriting from it in the test directory. Now mock out any implementations in the actual Base that you are not interested in with functions that do nothing. Example the Mock_base::Connect() may return SUCCESS return code. This way you can unit test the Derived:funcs() without modifying the source code.

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

Sidebar

Related Questions

I have a class API which has full code coverage and uses DI to
I have the following so far which I am trying to unit test: private
I have a WCF Ria service which invokes several wcf services (non Ria). I'm
i have the following code, which fails during runtime... var mock = new Mock<ControllerContext>();
I am using a mock object in RhinoMocks to represent a class that makes
I'm new to mock objects, but I understand that I need to have my
Here is the site mock-up I'm working on for my job: http://dev.arm.gov/~noensie/dqhands/cgi-bin/explorer . I'm
I use PowerMock to mock static methods. I need to verify order of static
Which of these is correct? var mockLogger = new Mock<EntLibLogger>(); mockLogger.Setup(i => i.CreateTracer(It.IsAny<string>())) .Returns((string
As part of a unit test I am trying to mock the return value

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.