BT

Your opinion matters! Please fill in the InfoQ Survey!

Unit Testing Tips from Google

| by Kurt Christensen Follow 0 Followers on Apr 27, 2007. Estimated reading time: 1 minute |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

The QA engineers behind the Google testing blog have been sharing their unit testing tips in an ongoing series titled "Testing on the Toilet":
We write flyers about everything from dependency injection to code coverage, and then regularly plaster the bathrooms all over Google with each episode, almost 500 stalls worldwide... We've decided to share this secret weapon with the rest of the world to help spread our passion for testing, and to provide a fun and easy way for you to educate yourself and the rest of your company about these important tricks and techniques.
Whimsical name - but some serious content. The latest installment ("Refactoring Tests in the Red") tackles a common problem - once a unit test suite becomes substantial, how can the unit tests themselves be refactored without accidentally invalidating the tests?
If you intentionally break the code under test, the failing test can show you that your assertions are still working. For example, if you were refactoring methods in CombineHarvesterTest, you would alter CombineHarvester, making it return the wrong results.

Check that the reason the tests are failing is because the assertions are failing as you'd expect them to. You can then (carefully) refactor the failing tests. If at any step they start passing, it immediately lets you know that the test is broken – undo! When you're done, remember to fix the code under test and make sure the tests pass again.
Other installments of "Testing on the Toilet" include:
  • Refactoring Tests in the Red (html / pdf)
  • Stubs Speed Up Your Unit Tests (html / pdf)
  • JavaScript: Simulating Time in jsUnit Tests (html / pdf)
  • Naming Unit Tests Responsibly (html / pdf)
  • Better Stubbing in Python (html / pdf)

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT