O'Reilly logo

Test Driven Development: By Example by Kent Beck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 20. Cleaning Up After

Invoke test methodInvoke setUp firstInvoke tearDown afterwardInvoke tearDown even if the test method failsRun multiple testsReport collected results

Sometimes tests need to allocate external resources in setUp(). If we want the tests to remain independent, then a test that allocates external resources needs to release them before it is done, perhaps in a tearDown() method.

The simpleminded way to write the test for de-allocation is to introduce yet another flag. All of those flags are starting to bug me, and they are missing an important aspect of the methods: setUp() is called before the test method is run, and tearDown() is called afterward. I'm going to change the testing strategy to keep a little log ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required