Question

This seems to be the common pattern that's emerging in some of the tests I've worked...

This seems to be the common pattern that's emerging in some of the tests I've worked on lately. We have a class, and quite often this is legacy code whose design can't be easily altered, which has a bunch of member variables.

There's some kind of "Initialize" or "Load" function which would put an object into a valid state. Only after it is initialized/loaded, are the members in the proper state so that other methods can be exercised.

So when we start writing tests, first test is "TestLoad" and all we put in there is exercising initialization logic. Then we might add one (or few) TestLoadFailureXXX tests and those are definitely valuable.

Then we start writing tests to verify other behaviors but all of them require the object to be loaded. So they all start by running exactly the same code as "TestLoad".

So my question: Is TestLoad even necessary? Do you take it out and let other tests simply exercise the loading? Or leave it so things are more explicit?

I know that each unit test function should have no (or as little as possible) overlap with other test functions, but it seems like in cases of loading, this is unavoidable. And whether we like it or not, if something in the loading code breaks, we will end up with a whole test suite of failures.

Is there another approach that I might be missing here?

Thank you for the responses. It definitely makes sense that you want to see "InitializationTest" and if that fails you know where to start looking.
In case it matters, this question is mostly about C++ and we use CppUnit framework. And now, thanks to sleske, I'll be constantly wishing that CppUnit supported test dependencies. Might have to hack something in one of these days :)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If the initialization fails, you would like that to show up in a test clearly labeled as testing the initialization, instead of in a test which nominally is about something else.

And if behavior dependant on initialization fails, when a test catches it, you would like to be confident that the error is in the nominally tested behavior, and not the initialization, which was covered in a seperate test.

So having a seperate initialization test helps you distinguish between different error conditions.

Add a comment
Know the answer?
Add Answer to:
This seems to be the common pattern that's emerging in some of the tests I've worked...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. List some of the various communities to which you belong (organizations, work, hobbies, fields of...

    1. List some of the various communities to which you belong (organizations, work, hobbies, fields of expertise, family). Give examples of some of the behavioral and language characteristics particular to each group? For instance, do you speak to your job supervisor in the same way you speak to your child or your best friend? Why might you interact with members of different communities differently?    2.What are some of your past experiences with writing? Please explain what you like and...

  • AQueue.java class AQueue implements Queue { private E queueArray[]; // Array holding queue elements private static...

    AQueue.java class AQueue implements Queue { private E queueArray[]; // Array holding queue elements private static final int DEFAULT_SIZE = 10; private int maxSize; // Maximum size of queue private int front; // Index of front element private int rear; // Index of rear element // Constructors @SuppressWarnings("unchecked") // Generic array allocation AQueue(int size) { //BUG #1: maxSize = size maxSize = size+1; // One extra space is allocated rear = 0; front = 1; queueArray = (E[])new Object[maxSize]; //...

  • Help with program /* Lab 7, Part E: Created by Celine Latulipe public class Lab7Parte {...

    Help with program /* Lab 7, Part E: Created by Celine Latulipe public class Lab7Parte { public static void main(String [] args) // TODO: put your code here to generate a random number between 0 and 20 // and then print out that many asterisks on a single line. { بہا } We were unable to transcribe this image/* Lab 7, Part F: Created by Celine Latulipe public class Lab 7PartF { public static void main(String [] args) { //...

  • This question is about java program. Please show the output and the detail code and comment.And...

    This question is about java program. Please show the output and the detail code and comment.And the output (the test mthod )must be all the true! Thank you! And the question is contain 7 parts: Question 1 Create a Shape class with the following UML specification: (All the UML "-" means private and "+" means public) +------------------------------------+ | Shape | +------------------------------------+ | - x: double | | - y: double | +------------------------------------+ | + Shape(double x, double y) | |...

  • The Question IS Which of these projects will actually be invested in? Which of the ones...

    The Question IS Which of these projects will actually be invested in? Which of the ones will people actually do? Investment and real interest rates The article is about how real interest rates drive planned investment. Think about the function investment as a function of real interest rates. Planned investment as a function of real interest rates. Talking about real interest rates, I'm really just talking about nominal interest rates factoring out or discounting what's going on with inflation. There...

  • Every day, we make many decisions based on our needs, our assets, and our desires and...

    Every day, we make many decisions based on our needs, our assets, and our desires and what is available to meet these. A Recommendation Report is simply a formalized written statement of this that businesses use to make decisions. They often use it to make decisions to purchase equipment or to make decisions to move or change something, perhaps even whether or not they need to hire workers. First, a business must decide what is the issue. In the case...

  • Instructions This discussion requires you to synthesize your knowledge about the relationships of...

    Instructions This discussion requires you to synthesize your knowledge about the relationships of health care concepts with your knowledge of effective patient teaching techniques. For each discussion you will select ONE Concept Analysis Diagram, the normal physiology of ONE of the interrelated concepts leading to ONE of the consequences (positive or negative). Be sure to limit your discussion to normal physiology. Do not present a disease process or delve into pathophysiology. Your target audience is your patient, so avoid medical...

  • Instructions This discussion requires you to synthesize your knowledge about the relationships of health care concepts...

    Instructions This discussion requires you to synthesize your knowledge about the relationships of health care concepts with your knowledge of effective patient teaching techniques. For each discussion you will select ONE Concept Analysis Diagram, the normal physiology of ONE of the interrelated concepts leading to ONE of the consequences (positive or negative). Be sure to limit your discussion to normal physiology. Do not present a disease process or delve into pathophysiology. Your target audience is your patient, so avoid medical...

  • SELF-CHECK Why did the first version of method search that passed the first test itemNotFirstElementInSingleElementArray contain...

    SELF-CHECK Why did the first version of method search that passed the first test itemNotFirstElementInSingleElementArray contain only the statement return −1? Assume the first JUnit test for the findLargest method described in Self-Check exercise 2 in section 3.4 is a test that determines whether the first item in a one element array is the largest. What would be the minimal code for a method findLargest that passed this test? PROGRAMMING Write the findLargest method described in self-check exercise 2 in...

  • Could I get some help with this assignment In this assignment, you'll write a program which...

    Could I get some help with this assignment In this assignment, you'll write a program which reads a text file, and prints a histogram of its word sizes. So, for example, the historgram should show the number of words of length 1, of length 2, etc., up to the number of words of length n, where n is some constant defined in your program. To obtain text files that are suitably long, you could try Project Gutenberg, a site containing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT