Join Kyle Sherman for an in-depth discussion in this video Huge execution times, part of Learning LayoutTest for iOS Development.
- [Instructor] Lastly, we have one other set of tests to look at. Let's take a look at ManyLabelsView.xib and see what this looks like. As you see here, we have a view with seven labels stacked vertically. It's a bit of a contrived example, but we just care about how many different elements that need input data for this common error. So, you can imagine you have a view with a bunch of different things that require input. For this, it's seven labels. Let's go to the layout test for this. ManyLabelsViewLayoutTests.swift.
Let's come down here, take out the underscore prefix so that it'll run and let's run the test, Command + U. Okay, it is attaching and it is testing. As you notice, usually our layout tests are pretty quick and it's about done by now, and this is still going. You can keep waiting if you'd like but I'm going to tell you that it's going to take forever. Literally. So, what is the problem here? Well, the tests are taking forever and that's because with the amount of sizes we have and the labels, with all of the different combinations that layout tests test, it will go through way too many combinations and will take much too long to go through all of them.
What can we do? First, let's stop this because it's crazy. You can either hit the Stop button or I like using Command + period. What we do is, we add, in runLayoutTests, a parameter called limitResults and here, it's an enum that takes one of two things. We can limit the sizes or the data combinations. The best thing to do, in my opinion, is the data combinations. Now, we run all the tests again, Command + U.
And there, we're done. Now it's running in normal time. If you ever notice layout tests are not finishing, you may need to use this parameter. This went through all the test combinations in a linear fashion, so you'll still get great coverage because most problems will be caught. I encourage you to look through the sample code in this project, as you may find some useful techniques.
- 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