The progressive developer knows that in this complex modern world, things aren’t always black-and-white, even in testing. Sometimes we know the software won’t return the best answer, or even a correct answer, for all input. You may be tempted to write…
To quell a lingering feeling of inadequacy, you took the time to build your own planetary death ray, a veritable rite of passage in the engineering profession. Congratulations. And you were feeling pretty proud until the following weekend, when you pur…
Because the Google C++ Testing Framework was opensourced last week, there will be episodes focusing on it published here in the future. Watch for them. I’ve reshuffled the schedule to get one out this week.Google C++ Testing Framework supports two fa…
You’re pair programming and, as many brilliant people are apt to do, talking out loud. “I’ll make a mock, inject it, and rerun the test. It should pa- …D’OH” Your partner notices the exception “ConnectionFactory not initialized”. “What?” she says…
When you want to test code that depends on something that is too difficult or slow to use in a test environment, swap in a test double for the dependency.A Dummy passes bogus input values around to satisfy an API.Item item = new Item(ITEM_NAME);Shoppin…
Full statement coverage may be necessary for good testing coverage, but it isn’t sufficient. Two places where statement coverage will be inadequate are branches and loops. In this episode, we’ll look at branches, and specifically the differences betwee…
It’s hard to test code that uses singletons. Typically, the code you want to test is coupled strongly with the singleton instance. You can’t control the creation of the singleton object because often it is created in a static initializer or static m…
Consider the following function, which modifies a client-supplied object:bool SomeCollection::GetObjects(vector* objects) const { objects->clear(); typedef vector::const_iterator Iterator; for (Iterator i = collection_….
Flaky tests make your life more difficult. You get failure notifications that aren’t helpful. You might become numb to failures and miss an actual failure condition. Your changes might get unfairly blamed for causing a flaky test to fail. Unfortunately…
How can a method be well tested when it’s inputs can’t be clearly identified? Consider this method in Java:/** Return a date object representing the start of the next minute from now */public Date nextMinuteFromNow() { long nowAsMillis = Sys…
Recently, somewhere in the Caribbean Sea, you implemented the PirateShip class. You want to test the cannons thoroughly in preparation for a clash with the East India Company. This requires that you run the crucial testFireCannonDepletesAmmunition() me…
Code coverage (also called test coverage) measures which lines of source code have been executed by tests. A common misunderstanding of code coverage data is the belief that:My source code has a high percentage of code coverage; therefore, my code is w…
In the movie Amadeus, the Austrian Emperor criticizes Mozart’s music as having “too many notes.” How many tests are “too many” to test one function?Consider the method decide:public void decide(int a, int b, int c, int d, &nbs…
How quickly can you… …read all 25 words out loud: RED, GREEN, BLUE, … (Try it now!) …say all 25 colors out loud: GREEN, YELLOW, WHITE… (Try it now!) Did the second task require more time and effort? If so, you’re experiencing the Stroop Eff…