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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:50:56+00:00 2026-06-08T11:50:56+00:00

I work with a distributed system that has unit and integration tests. I am

  • 0

I work with a distributed system that has unit and integration tests. I am trying to save time and maintenance efforts by reusing code between integration and unit tests. For this I implemented an interface and 2 classes: fake and real. Fake class returns some stubbed data, and real class makes a few calls to other distributed services.

Current structure of my projects

/BaseTest              
   interface IFoo
-------------------------------------
/UnitTest
   class FakeFoo : IFoo

   [TestFixture]
   class FooTest {...} //uses FakeFoo
-------------------------------------
/IntegrationTest
   class RealFoo : IFoo

   [TestFixture]
   class FooTest {...} //uses RealFoo

I want to somehow reuse code for both tests, so if I have a test

[Test]
public void GetBarIsNotNullTest()
{
    var foo = IoC.Current.Resolve<IFoo>();
    Bar actual = foo.GetBar();
    Assert.IsNotNull(actual);   
}

I want this test to run with both implementations: RealFoo and FakeFoo. So far I thought about copy-pasting tests between /UnitTest and /IntegrationTest projects, but this doesn’t sound right.

System is written in C#, but I believe this question is language agnostic.

Anyone has better ideas? Am I doing this wrong?

  • 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-08T11:50:57+00:00Added an answer on June 8, 2026 at 11:50 am

    Even though others had good points in their answers, this is what I ended up doing

    I created a base class for unit and integration tests

    [TestFixture]
    public class FooBase
    {
        [Test]
        public void GetBarIsNotNullTest()
        {
            var foo = IoC.Current.Resolve<IFoo>();
            Bar actual = foo.GetBar();
            Assert.IsNotNull(actual);   
        }
    
        //many other tests  
    }
    

    And then two derived classes from the FooBase. These class will only have the SetUp and nothing else. i.e.:

    [TestFixture]
    public class UnitTestFoo : FooBase
    {
        [SetUp]
        public void SetUp()
        {
            IoC.Current.Register<IFoo, FakeFoo>();        
        }
    
        //nothing else here
    }
    
    [TestFixture]
    public class IntegrationTestFoo : FooBase
    {
        [SetUp]
        public void SetUp()
        {
            IoC.Current.Register<IFoo, RealFoo>();        
        }
    
        //nothing else here
    }
    

    So if I now run my tests, I get the tests defined in the parent class FooBase run twice for unit tests class and integration tests class with their own real and fake objects. This works because of the inheritance of the test fixtures.

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

Sidebar

Related Questions

I work with unordered_set . Here it's written that it has a reserve function
We use MVC controllers that access System.File.IO in our application and they work fine
Consider the following distributed system that uses OAuth 2.0 for authorization and OpenID 2.0
I've been working on a comprehensive build system that performs distributed builds on multiple
We are building a system that would benefit greatly from a Distributed Caching mechanism,
At my work we are running a group of tests that consist of about
I'd like to work on a 2-3 month long project (full time) that involves
Our product is a distributed system. The modules I work on are fairly new,
I am building a distributed system that consists of potentially millions of clients which
I am trying to develop a network safe decentralized replication based distributed system. I

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.