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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:16:37+00:00 2026-05-26T05:16:37+00:00

I have a function foo() that in turn calls function bar(). How can I

  • 0

I have a function foo() that in turn calls function bar(). How can I confirm that bar actually gets called?

Example of complex business logic method to test:

class Car
{
  IStarter starter
  IKeyhole keyhole
  IBrakePedal pedal
  Drive()
  {
    keyhole.InsertKey()
    keyhole.RotateToStart()
    starter.TurnEngineOver()

    ...

    if (pedal.Pressed)
      this.SlowDown()
  }
}

I have a method that brings together 6 external dependencies (interfaces with methods), and runs them in a sequence, order is not important. I would like to make sure each was called. In another test, I’d like to tweak conditionals and ensure that a subset was called.

In C# with Moq, I have a full page of setup code.

Here’s what I’d like to see in my unit test:

let `check that brake pedal slows down car` =
   let car = new Car()
   car.pedal.Pressed <- true
   car.Drive()
   car.SlowDown |> wasCalled

The rest should be inferred from usage. I have a real need to reduce noise in tests.

  • 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-26T05:16:38+00:00Added an answer on May 26, 2026 at 5:16 am

    The closest thing I know to what you want is an AutoMockingContainer.

    In a nutshell, it’s an IoC container that gives you a Car with all IStarter, IKeyhole, IBrakepedal stubbed out and wired to the Car instance, without you explicitly registering any of them. You then proceed to set your expectations as usual (in your case, “car.SlowDown() was called”), then call the method under test.

    The specifics depend on the IoC container and mocking framework used. The original one was written with Windsor and an old version of Rhino Mocks, but now there are AMC for StructureMap, Ninject, Autofac + Moq, etc.

    You could start with one of these and wrap it to make it more idiomatic in F#.

    It has its downsides, it’s not something I’d recommend using “by default”.

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

Sidebar

Related Questions

I have a function that is called like this: foo($object->ID); and in the function
If I have a function foo() that windows has implemented in kernel32.dll and it
Say I have a function foo that I want to call n times. In
I have a base class Foo that has an Update() function, which I want
I have a function that accepts a variable number of parameters: foo (Class... types);
I have some third-party Javascript that has statements like this: FOO = function() {
Let's say that I have an Erlang function, with spec. -spec foo(integer(), string()) ->
I have a function foo that takes a NxM numpy array as an argument
I have a function foo(i) that takes an integer and takes a significant amount
Second time I've ran into this... I have function foo() that has a helper

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.