LayoutTest tests for accessibility and Auto Layout issues, as well as many others issues—sometimes without writing anything at all in your test code. It also automates the testing of several layout issues using its simple syntax that ensures that there are no problems with your user interface elements.
- [Instructor] LayoutTest allows you to very easily test the layouts of your views for many types of issues. Many of the tests are automatically run by the library. In this video, you will learn about the tests that can be automatically be run on your layouts and what types of tests you can write yourself. LayoutTest can test any type of view. That means anything that inherits from UI view, whether it be a UITableViewCell, a UICollectionViewCell, or a view from a view controller. This view controller can be defined even in a storyboard or a ZIB file.
We will use this view as our example throughout this video. This view represents a cell in a UITableView or a collection view. As you see, it has a title, a subtitle, and a button on the right. First let's look at what LayoutTest tests for you automatically. LayoutTest automatically checks that no views overlap each other. As you see, the title should not be overlapping the button in this case. You can also add exceptions though. So if you have a background view, that's obviously going to have views overlapping it.
LayoutTest also automatically tests that a view is contained within its superview. As you see in this slide, the button is outside of the borders of the cell. LayoutTest automatically makes sure that there are not Auto Layout errors. In this case, we see two conflicting constraints. The subtitle has a constraint set from the trailing edge to the leading edge of the button but also constraint set from the trailing edge to the trailing edge of its superview. These two would conflict and would cause undefined behavior.
LayoutTest will therefore fail our test. LayoutTest will also make sure that there are no ambiguous layouts in Auto Layout. You must specify both horizontal and vertical constraints for every view. Here we only specify the horizontal constraints so this would fail the test. LayoutTest will also automatically check for accessibility issues. It makes sure there are no missing accessibility labels, if that check is turned on, which it is automatically. And if there's an accessibility identifier, you must have an accessibility label.
You don't want a voiceover user to hear your identifier instead of your label that is meant to be read. You can also make sure that the content of your views is correct, such as make sure a UILabel has the proper text in it or a UIImageView has the correct UIImage. Aside from the tests that are automatically run, you'll want to verify the layout of your view as what you expect given all of the different sets of data that are used. You can also make sure that your views are aligned properly, such as to the left of another view or above another view.
And LayoutTest provides very simple Helper APIs for checking the layout of your UI elements as you'll see in coming videos. In this video, we learned about all of the different automatic tests that LayoutTest runs for you with very minimal code required. Then, you are also able to write custom assertions to ensure that each layout meets your specifications. LayoutTest allows you to easily test all the properties of your views.
Released
3/9/2017- Installing the library
- Specifying test data
- Reviewing property-based testing
- Using test data and writing the LayoutTest test
- Testing views at different sizes
- Debugging with snapshots
- Dealing with common errors
- Advanced debugging tips
- Exploring catalog view
Share this video
Embed this video
Video: What does LayoutTest test?