Build Temporary Tests as a Safety Net

Before you apply a splinter refactoring you have to ensure that you won’t break the behavior of the code. Unfortunately, most hotspots lack adequate test coverage and writing unit tests for a hotspot is often impossible until we’ve refactored the code. Let’s look at an example from the Android codebase that we discussed earlier.

As you see in the figure, there’s a big difference in the amount of application code in Android’s core package versus the amount of test code in the test package.

images/patterns/android-hotspot-test.png

That figure should put fear into any programmer planning a refactoring, because the unit test for the main hotspot, ActivityManagerService.java ...

Get Software Design X-Rays 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.