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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:50:44+00:00 2026-06-10T01:50:44+00:00

I have problem with faking my class: Class A has a method: protected virtual

  • 0

I have problem with faking my class:

Class A has a method:

protected virtual int method(int argument)
{
    implementation
    return int;
}

Class B extends class A and overrides the method:

protected override int method(int argument)
{
      int result = base.method(argument);
      implementation
      return result + 1;
}

I need to mock class B and test the method function. The problem is that I need to avoid calling the base.method(argument) function. I just need to test my method implementation, and mock that function to return an int.

How can I do it with FakeItEasy? Or other mocking frameworks?

UPDATE

Problem solved by:
making function:

int MethodCaller(int argument)
{
    base.method(argument);
}

and executing it in my class B “method” function. Than mocking MethodCaller function

  • 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-10T01:50:46+00:00Added an answer on June 10, 2026 at 1:50 am

    You can do it with helper class + one more helper method, but I realy don’t like this solution:

    public class A
    {
        protected virtual int method(int argument)
        {
            return argument;
        }
    
        public int result(int argument)
        {
          return method(argument);
        }
    }
    
    public class B : A
    {
        protected override int method(int argument)
        {
            return baseMetod(0) + 1;
        }
    
        protected virtual int baseMetod(int argument)
        {
          return base.method(argument);
        }
    }
    
    public class C : B
    {
        protected override int baseMetod(int argument)
        {
          return 5;
        }
    }
    

    so in test you can call new C().Result(10)

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

Sidebar

Related Questions

I am facing a problem. I have a Class that extends listactivity and its
i am facing one problem.i have a class named ReportingService and it should be
I have a terrible problem that hopefully has a very simple answer. I am
Hey guys here is the problem i am facing i have a User class
Let's say I have a class which has three properties as below. public class
I've got a Coordinate class, which has an add(Coordinate) method. When writing unit tests
I have this service: public class AAAService extends Service { private Intent requestService; private
Im facing following problem I have created mentioned condition, but when I choose y
I have just installed RVM in my machine and facing problem with rvmrc file,
I am facing problem to get variable from query string. I have used htaccess

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.