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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:03:24+00:00 2026-05-12T00:03:24+00:00

So I have a factory class and I’m trying to work out what the

  • 0

So I have a factory class and I’m trying to work out what the unit tests should do. From this question I could verify that the interface returned is of a particular concrete type that I would expect.

What should I check for if the factory is returning concrete types (because there is no need – at the moment – for interfaces to be used)? Currently I’m doing something like the following:

[Test]
public void CreateSomeClassWithDependencies()
{
    // m_factory is instantiated in the SetUp method
    var someClass = m_factory.CreateSomeClassWithDependencies();

    Assert.IsNotNull(someClass);
}

The problem with this is that the Assert.IsNotNull seems somewhat redundant.

Also, my factory method might be setting up the dependencies of that particular class like so:

public SomeClass CreateSomeClassWithDependencies()
{
    return new SomeClass(CreateADependency(), CreateAnotherDependency(),
                         CreateAThirdDependency());
}

And I want to make sure that my factory method sets up all these dependencies correctly. Is there no other way to do this then to make those dependencies public/internal properties which I then check for in the unit test? (I’m not a big fan of modifying the test subjects to suit the testing)

Edit: In response to Robert Harvey’s question, I’m using NUnit as my unit testing framework (but I wouldn’t have thought that it would make too much of a difference)

  • 1 1 Answer
  • 1 View
  • 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-12T00:03:25+00:00Added an answer on May 12, 2026 at 12:03 am

    Often, there’s nothing wrong with creating public properties that can be used for state-based testing. Yes: It’s code you created to enable a test scenario, but does it hurt your API? Is it conceivable that other clients would find the same property useful later on?

    There’s a fine line between test-specific code and Test-Driven Design. We shouldn’t introduce code that has no other potential than to satisfy a testing requirement, but it’s quite alright to introduce new code that follow generally accepted design principles. We let the testing drive our design – that’s why we call it TDD 🙂

    Adding one or more properties to a class to give the user a better possibility of inspecting that class is, in my opinion, often a reasonable thing to do, so I don’t think you should dismiss introducing such properties.

    Apart from that, I second nader’s answer 🙂

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

Sidebar

Related Questions

I have this factory: FactoryGirl.define do factory :from_sector, class: Sector do sequence(:name) { |n|
I have a factory class that serves out a bunch of properties. Now, the
I have a custom connection factory class (which inherits from psycopg2.extensions.connection ) that I
i have simple singleton that sets pdo object from factory class , in the
I have a factory class that decides which of four available subclasses it should
Hi i have this class to instantiate DAL classes: public class Factory { public
I'm trying to implement what I believe is a factory class. I have an
I have the following (simplified) code from a generic factory class: - (id) invokeSetup:
I have a factory class that returns concrete instances inheriting from an abstract type.
I have a factory class, DocumentLoaderFactory , which simply returns an instance that implements

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.