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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:56:43+00:00 2026-06-11T01:56:43+00:00

I have an interface IFoo public interface IFoo { void DoSomeStuff(); } And I

  • 0

I have an interface IFoo

public interface IFoo
{
    void DoSomeStuff();
}

And I have two derived types FooImpl1 and FooImpl2:

public class FooImpl1 : IFoo
{
    public void DoSomeStuff()
    {
        //...
    }
}

public class FooImpl2 : IFoo
{
    public void DoSomeStuff()
    {
        //Should do EXACTLY the same job as FooImpl1.DoSomeStuff()
    }
}

I have a test class which tests IFoo contract of FooImpl1 :

    private static IFoo FooFactory()
    {
        return new FooImpl1();
    }

    [Fact]
    public void TestDoSomeStuff()
    {
        IFoo foo = FooFactory();

        //Assertions.
    }

How can I reuse this test class to test both FooImpl1 and FooImpl2?

  • 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-11T01:56:44+00:00Added an answer on June 11, 2026 at 1:56 am

    How about having base class for IFoo tests with abstract method returning appropriate implementation?

    public abstract class FooTestsBase
    {
        protected abstract IFoo GetTestedInstance();
    
        [Fact]
        public void TestDoSomeStuff()
        {
            var testedInstance = GetTestedInstance();
            // ...
        }
    }
    

    Now, all derived types have to do is simply provide that one instance:

    public class FooImpl1Tests : FooTestsBase
    {
        protected override IFoo GetTestedInstance()
        {
            return new FooImpl1();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code internal interface IFoo { void foo(); } public class A :
I have interface Foo public interface Foo { public void test(); } Class FooChild
I have the following example code using MEF: public interface IFoo<T> {} public class
I have the following interface in Java public interface IFoo { public abstract void
Lets say I have the following: public interface IFoo { void Foo(); } public
I have an interface, and some classes that inherit from it. public interface IFoo
Consider the following code. public interface IFoo { } public class Bar { public
I have an interface: public interface IFoo{ string Bar{ get; set; } } and
I have an interface with a property like this: public interface IFoo { //
I have two implementations of interface IFoo : Foo1 and Foo2 . I need

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.