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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:03:01+00:00 2026-06-01T11:03:01+00:00

I have some classes(call it Class A) which I would like to unit test

  • 0

I have some classes(call it Class A) which I would like to unit test but it uses some classes(call it Class B) with some static methods.

To remove reference to these classes with static methods I have to refactor them to be instance methods and inject into Class A.

Issue is Class A has lots of services(Not only class B) its seems to depend on?

What is the best option in this scenario? Have a constructor that has a lot of parameters that can take in these services?

Or is there something wrong with my design the fact that class A has so many dependencies?

Thanks

  • 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-01T11:03:02+00:00Added an answer on June 1, 2026 at 11:03 am

    Issue is Class A has lots of services(Not only class B) its seems to depend on?

    Several dependencies are usually indicating a code smell. Your class is most likely breaking Single Responsibility Principle.

    Try to break down the class into smaller classes.

    Unit tests are a good quality indicator. Classes that are hard to test are often violating one or more of the SOLID principles.

    What is the best option in this scenario? Have a constructor that has
    a lot of parameters that can take in these services?

    Constructor injection is always the preferred way since it’s easy to tell what dependencies a class has.

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

Sidebar

Related Questions

I have some classes layed out like this class A { public virtual void
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have some classes extended this way: class Baseresidence extends CActiveRecord { public static
I would like to initialize a class, then call an attribute which was set
I have some classes which extends a superclass, and in the JSP I want
I have some classes which are parameterized via their constructor. I need to provide
I have some code I would like to execute very early in the lifecycle
I'm trying to solve a problem where I have some classes in which I
I have a base abstract class with several classes which extend and override it,
I have a main Activity and a Dialog through which I would like to

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.