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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:01:50+00:00 2026-05-25T03:01:50+00:00

I have a factory class that creates an object based on a parameter it

  • 0

I have a factory class that creates an object based on a parameter it receives. The parameter is an identifier that tells it which object it should create.
Its first step is to use the data access layer to pull information for the object.
Its next step is to do some cleansing / transformations on the data.
Finally it creates the required object and returns it.

I want to ensure that the cleansing / transformation step went OK but the object that it returns does not expose any state so I’m not sure how to test it easily.

The data access layer and the database structure can’t change because they have to work with legacy code.

I could test it further on in the system after the object gets used but that would lead to big tests that are hard to maintain.

I’ve also thought of exposing the state of the object, or putting the responsibility in another class and testing that, but both those options seem like I’m changing the system for testing.

Any thoughts on other ways to test something like this?

  • 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-25T03:01:50+00:00Added an answer on May 25, 2026 at 3:01 am

    It sounds to me like you are trying to test too much within a unit test.

    This is a symptom of your Unit trying to do too much.

    You are trying to do three things here.

    1. Get data from the data access layer.
    2. Clean the data.
    3. Build the object

    To fix I would move each of these responsibility into their own units ( classes / methods ) as you have suggested. Then you can test each unit on its own.

    You are hesitant to do this as you don’t want to change the system for testing. However, the advantage of unit testing is that it highlights flaws in the design. Not only are you changing the system for testing, you are improving it and making it more granular and thus more maintainable and reusable.

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

Sidebar

Related Questions

I have a factory-type class that creates its products based on the traits of
In C++ for Windows, I have some object factory that is supposed to create
I have a factory that creates objects of class MyClass , returning already generated
Inside a container object, I have created a class Factory , that is responsible
I have a factory class that populates objects with data. I want to implementing
I have a factory that returns an interface FormatService : public class FormatServiceFactory {
I have certain classes that have common feature - class factory that I need
I have the following code for factory design pattern implementation. class Pen{ public: virtual
I have a factory that builds the objects with longest lifetime in my application.
I have a object built through a factory containing my parameters read from the

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.