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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:42:18+00:00 2026-05-29T10:42:18+00:00

I have often seen tests where canned inputs are fed into a program, one

  • 0

I have often seen tests where canned inputs are fed into a program, one checks the outputs generated against canned (expected) outputs usually via diff. If the diff is accepted, the code is deemed to pass the test.

Questions:

1) Is this an acceptable unit test?

2) Usually the unit test inputs are read in from the file system and are big
xml files (maybe they represent a very large system). Are unit tests supposed
to touch the file system? Or would a unit test create a small input on the fly
and feed that to the code to be tested?

3) How can one refactor existing code to be unit testable?

  • 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-29T10:42:19+00:00Added an answer on May 29, 2026 at 10:42 am

    Output differences

    If your requirement is to produce output with certain degree of accuracy, then such tests are absolutely fine. It’s you who makes the final decision – “Is this output good enough, or not?”.

    Talking to file system

    You don’t want your tests to talk to file system in terms of relying on some files to exists somewhere in order for your tests to work (for example, reading values from configuration files). It’s a bit different with tests input resources – you can usually embed them in your tests (or at least test project), treat them as part of codebase, and on top of that they usually should be loaded before test executes. For example, when testing rather large XMLs it’s reasonable to have them stored as separete files, rather than strings in code files (which sometimes can be done instead).

    Point is – you want to keep your tests isolated and repeatable. If you can achieve that with file being loaded at runtime – it’s probably fine. However it’s still better to have them as part of codebase/resources than standard system file lying somewhere.

    Refactoring

    This question is fairly broad, but to put you in the right direction – you want to introduce more solid design, decouple objects and separate responsibilities. Better design will make testing easier and, what’s most important – possible. Like I said, it’s broad and complex topic, with entire books dedicated to it.

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

Sidebar

Related Questions

I have often seen the spinning gears OpenGL example ( I think originally done
I have often seen an init() within the constructor of AS3 classes, sometimes even
I often have data in Excel or text that I need to get into
I have often seen the queries written in SQL in CAPITAL LETTERS . Though
I have often seen stylesheets written where you have something like this: #anyelement {
Browsing through some C++ questions I have often seen comments that a STL-friendly class
I've often seen line_item tables for orders or invoices that copy one or more
I've seen second one in another's code and I suppose this length comparison have
I have often seen cases where in a series of printf statements that ask
I have seen people often use a separate table to store relations between tables.

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.