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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:06:31+00:00 2026-05-17T21:06:31+00:00

Is it generally accepted that you cannot test code unless the code is setup

  • 0

Is it generally accepted that you cannot test code unless the code is setup to be tested?

A hypothetical bit of code:

public void QueueOrder(SalesOrder order)
{
   if (order.Date < DateTime.Now-20)
      throw new Exception("Order is too old to be processed");
   ...  
}

Some would consider refactoring it into:

protected DateTime MinOrderAge;
{
   return DateTime.Now-20;
}

public void QueueOrder(SalesOrder order)
{
   if (order.Date < MinOrderAge)
      throw new Exception("Order is too old to be processed");
   ...
}

Note: You can come up with even more complicated solutions; involving an IClock interface and factory. It doesn’t affect my question.

The issue with changing the above code is that the code has changed. The code has changed without the customer asking for it to be changed. And any change requires meetings and conference calls. And so i’m at the point where it’s easier not to test anything.

If i’m not willing/able to make changes: does it make me not able to perform testing?

Note: The above pseudo-code might look like C#, but that’s only so it’s readable. The question is language agnostic.

Note: The hypothetical code snippet, problem, need for refactoring, and refactoring are hypothetical. You can insert your own hypothetical code sample if you take umbrage with mine.

Note: The above hypothetical code is hypothetical. Any relation to any code, either living or dead, is purely coincidental.

Note: The code is hypothetical, but any answers are not. The question is not subjective: as i believe there is an answer.


Update: The problem here, of course, is that i cannot guarantee that change in the above example didn’t break anything. Sure i refactored one piece of code out to a separate method, and the code is logically identical.

But i cannot guarantee that adding a new protected method didn’t offset the Virtual Method Table of the object, and if this class is in a DLL then i’ve just introduced an access violation.

  • 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-17T21:06:32+00:00Added an answer on May 17, 2026 at 9:06 pm

    The answer is yes, some code will need to change to make it testable.

    But there is likely lots of code that can be tested without having to change it. I would focus on writing tests for that stuff first, then writing tests for the rest when other customer requirements give you the opportunity to refactor it in a testable way.

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

Sidebar

Related Questions

When writing application code, it's generally accepted that premature micro -optimization is evil, and
It is generally accepted that the use of cursors in stored procedures should be
It's generally accepted that copy and paste programming is a bad idea, but what
With SQLServer, it seems to be generally accepted that adding a SELECT SCOPE_IDENTITY() to
It seems that the generally accepted approach to launch a URL is to call
Generally, MVC frameeworks have a structure that looks something like: /models /views /controllers /utils
Generally when I use ClickOnce when I build a VB.NET program but it has
Generally the database server is the biggest, most expensive box we have to buy
Generally, how bad of a performance hit is storing a file in a database
Generally, when using the conditional operator, here's the syntax: int x = 6; int

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.