Overview¶
This library helps you quickly write unit tests which test the layout of your views. These tests are run as part of your unit test suite. It is a property-based testing library, so it will run each test multiple times with different inputs.
Why Use This Library?¶
- It’s easy to write layout tests for views in just a few lines of code.
- It’s much faster to write than a UI automation test.
- It automatically tests for all kinds of edge cases you may have not considered when writing your view.
- The tests run fast (they’re just unit tests).
- The tests are stable and deterministic.
- The library helps stop regressions in your layout logic.
What this Library doesn’t do¶
- This library doesn’t test flows. You can’t test tap targets or view transitions. For this, you’ll need to use UI automation tests.
- This library doesn’t take screenshots of views and compare them. Instead, you are checking properties of the UIView object for correctness.
General Flow¶
- You define a spec for the data that should inflate this view. Effectively, this is mock data.
- You define how the view gets built. This is usually a couple of lines of code (init and inflate).
- You write your tests by asserting properties on the view that should always be true. For example, you may check that one view’s width is the same as another. You should check any layout logic which you’ve added to your view class.
- The testing framework creates many combinations of the data and inflates the view multiple times running the tests each time. In this way, you can write one test which tests hundreds of edge cases with no extra work. These edge cases include