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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:25:19+00:00 2026-05-13T07:25:19+00:00

or can the class be implementing an abstract class also?

  • 0

or can the class be implementing an abstract class also?

  • 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-13T07:25:19+00:00Added an answer on May 13, 2026 at 7:25 am

    To mock a type, it must either be an interface (this is also called being pure virtual) or have virtual members (abstract members are also virtual).

    By this definition, you can mock everything which is virtual.

    Essentially, dynamic mocks don’t do anything you couldn’t do by hand.

    Let’s say you are programming against an interface such as this one:

    public interface IMyInterface
    {
        string Foo(string s);
    }
    

    You could manually create a test-specific implementation of IMyInterface that ignores the input parameter and always returns the same output:

    public class MyClass : IMyInterface
    {
        public string Foo(string s)
        {
            return "Bar";
        }
    }
    

    However, that becomes repetitive really fast if you want to test how the consumer responds to different return values, so instead of coding up your Test Doubles by hand, you can have a framework dynamically create them for you.

    Imagine that dynamic mocks really write code similar to the MyClass implementation above (they don’t actually write the code, they dynamically emit the types, but it’s an accurate enough analogy).

    Here’s how you could define the same behavior as MyClass with Moq:

    var mock = new Mock<IMyInterface>();
    mock.Setup(x => x.Foo(It.IsAny<string>())).Returns("Bar");
    

    In both cases, the construcor of the created class will be called when the object is created. As an interface has no constructor, this will normally be the default constructor (of MyClass and the dynamically emitted class, respectively).

    You can do the same with concrete types such as this one:

    public class MyBase
    {
        public virtual string Ploeh()
        {
            return "Fnaah";
        }
    }
    

    By hand, you would be able to derive from MyBase and override the Ploeh method because it’s virtual:

    public class TestSpecificChild : MyBase
    {
        public override string Ploeh()
        {
            return "Ndøh";
        }
    }
    

    A dynamic mock library can do the same, and the same is true for abstract methods.

    However, you can’t write code that overrides a non-virtual or internal member, and neither can dynamic mocks. They can only do what you can do by hand.

    Caveat: The above description is true for most dynamic mocks with the exception of TypeMock, which is different and… scary.

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

Sidebar

Related Questions

Can anyone please explain me the meaning of implementing Map class and how should
I can't find any documentation on implementing a class that inherits System.Windows.Media.Brush - what
Having such class can I instatiate it in place? abstract class Mammal { public
I have one main interface and an abstract class implementing all derivable methods (that
Can I leave an abstract class that implements interfaces empty and imply that all
I'm working on an abstract class where the implementing class needs to implement a
What is use of an abstract class implementing an interface? In which scenario would
Can a class return an object of itself. In my example I have a
Can a class extend two or more classes in Objective-C?
Can singleton class be static?

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.