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

  • Home
  • SEARCH
  • 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 60983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:14:50+00:00 2026-05-10T18:14:50+00:00

In my question As a mockist TDD practitioner, should I mock other methods in

  • 0

In my question As a “mockist” TDD practitioner, should I mock other methods in the same class as the method under test?, Avdi answered ‘Personally I think that mocking on self is almost always a code smell. It’s testing the implementation rather than the behavior.’ He may be right, but often I can’t distinguish between the implementation and the behavior.

I have another example (in Python-style pseudo-code) that may lead to helpful answers:

class Consumer:      def spec_dirpath:         client = VCS.get_connection(self.vcs_client_name)         client.sync()         return client.dirpath()      def spec_filepath:         filepath = os.path.join(spec_dirpath(), self.spec_filename)         if not os.path.exists(filepath):             raise ConsumerException         return filepath      def get_components:         return Components.get_components_from_spec_file(self.spec_filepath()) 

The idea here is that the get_components method calls the spec_filepath method in order to get a path to a file that the get_components_from_spec_file Components class method will read a list of components from. The spec_filepath method in turn calls spec_dirpath, which syncs the directory containing the spec file from the VCS system and returns the path to that directory. (Try not to look for bugs in this code–it’s pseudo-code, after all.)

I’m looking for advice on how to test these methods…

Testing spec_dirpath should be quite straightforward. I can mock the VCS class and have it return a mock object and confirm the appropriate methods are called (and that the spec_dirpath method returns what the mock’s dirpath method returns).

But if I don’t mock spec_dirpath while testing spec_filepath, how do I avoid duplicating the same test code from the spec_dirpath code in the spec_filepath test? And if I don’t mock spec_filepath while testing get_components, how do I avoid duplicating the test code from both spec_filepath and spec_dirpath?

  • 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. 2026-05-10T18:14:51+00:00Added an answer on May 10, 2026 at 6:14 pm

    Unit testing works better with some form of dependency injection. In this case because you are creating the Client in the code you create a dependency in your test that requires some form of dynamic mock to cope with. (We’d use a partial mock in this case to mock our calls that create dependencies to avoid having to test those dependencies as well).

    If you inject the dependency on startup (i.e. Pass in a client object) then you can mock it easily and not have major difficulties testing just the one class.

    So you need either a partial mock or a dependency injection solution to meet those objectives.

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

Sidebar

Related Questions

Question: What is the standard method for accessing back end data, which logon should
Question: I wrote a method to retrieve a SQL result as a list of
Question: I want to test an if statement in PostgreSQL: IF (SELECT COUNT(*) FROM
Question from a Linux/Mac developer: I have compiled a 32-bit .dll (release flavor) under
I want to test a java method that has an enhanced for on it
Question i asked earlier along the same lines - jQuery - Selecting a child
Question: What is the Zephyr ASDL and how does it relate to other compiler
question is bit different than other questions regarding this. I had a similar issue
Question: Why is it that holdDate under function Check(), show Nothing while debugging, I
Question: I use the bidirectional dicionary class I found here: Bidirectional 1 to 1

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.