7

Test Setup and Teardown

Have you ever worked on a project where you needed to prepare your work area first? Once ready, you can finally do some work. Then, after a while, you need to clean up your area. Maybe you use the area for other things and can’t just leave your project sitting around or it would get in the way.

Sometimes, tests can be a lot like that. They might not take up table space, but sometimes they can require an environment setup or some other results to be ready before they can run. Maybe a test makes sure that some data can be deleted. It makes sense that the data should exist first. Should the test be responsible for creating the data that it is trying to delete? It would be better to wrap up the data creation inside its ...

Get Test-Driven Development with C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.