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

The Archive Base Latest Questions

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

I am fairly new to TDD but have been using it for long enough

  • 0

I am fairly new to TDD but have been using it for long enough to understand how to use mocks, stubs, dependency injection, inversion of control to solve ‘similar’ problems… but for some reason I feel very uneasy about using dependency injection and passing in an ‘IThread’ (or similar).

To give it some basic context – I am trying to add unit tests to a legacy application and I am unsure of how to unit test a class who’s constructor spawns two threads.

Is the only option to use dependency injection?

If so what about the functionality that the threads bring? As it stands the threads both run while(true) loops and never exit the loop (unless the application is terminating). Inside the loops there are reasonable chunks of code and it’s this code that I really want to have under test.

To make matters worse I don’t want to pull all the functionality out of the loops and into public methods (I’m only testing public methods as my tests exist in another project) as it will really decrease the easy of use of the class elsewhere in the code.

Any suggestions?

  • 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-13T12:19:26+00:00Added an answer on May 13, 2026 at 12:19 pm

    Could you pull the functionality into internal methods and use InternalsVisibleTo instead? Even if you’d really want them to be private, this is a reasonable compromise solution.

    If your threads would normally run forever, that does make it very hard to test… and it sounds like you really should be testing the “what the threads do” part separately, if they don’t depend on being in separate threads.

    One option which is occasionally useful is to have an IScheduler type of interface – ask that to execute an action wherever it sees fit; the production one would create a new thread, but your test one could run the action within the existing thread (or on a thread you had control over within your test code). I’m not sure that’s appropriate for your situation here, where the thread would run forever, but you might want to think about it in other situatoins.

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

Sidebar

Related Questions

I'm fairly new to programming in general but have been working with Java for
Fairly new to Jquery here.... but one thing I have been told and being
Fairly new to socket programming, but I've been assigned with a whopper of project.
Am fairly new to using MySQL and a total novice at Perl but am
Fairly new to asp.net Mvc and jquery. Have the following code working fine, but
Hi fairly new to using MVC radio buttons. I have some code: @Html.RadioButtonFor(modelItem =>
Fairly new to wpf, using the galasoft mvvm templates. I have two relaycommands that
First let me state that, despite being a fairly new practitioner of TDD, I'm
I am new to fairly new to AS3 and I have found myself needing
I am fairly new to C++ and I have seen a bunch of code

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.