5.7. Pixel perfection

Pixel perfection is a special case of primitive assertion and magic numbers. The reason why I felt it should be included in this catalog of test smells is because it’s so frequent in domains dealing with computer graphics, an area where people tend to report difficulties in testing their code.

In essence, the smell of pixel perfection floats around places where a test calls for a perfect match between expected and actual generated images, or when a test anticipates a given coordinate in a generated image to hold a pixel of a certain color. Such tests are notoriously brittle and generally break down with even the smallest changes in the input.

Let’s examine this anti-pattern with an example from a project I worked on some ...

Get Effective Unit Testing 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.