Unit testing is the most stable and reproducible form of testing; however, there has never been a great way to test your UIView or UIViewController with unit tests. LayoutTest solves this issue. This video explains what's different about LayoutTest and why it's important. Learn about how LayoutTest helps you test Interface Builder files (XIB), UIViewController subclasses, UIView subclasses, and anything that contains an instance of UIView.
- [Instructor] There are many different ways to test your code and many libraries created to help make that process easier and more effective. In this video, we will discuss some of the different types of testing and how layout test is different. Manual testing can be time consuming, error prone, but sometimes it can be the only choice. Automation is always a better option as you don't need to tie up useful resources manually testing each thing. There are two main categories of automated tests that we care about. Unit Tests and UI Automation Tests which are also called Integration Tests.
Unit tests tests individual units or functions of code. You isolate small pieces of functionality in the form of the actual functions you write and write tests to actually test those things. They're very low level and they use framework such as XCTest and Xcode and they are very fast to run and stable. There are many different options for UI Automation Tests frameworks such as UI Automator by Apple, EarlGrey by Google, or KIF by Square. He's introduced many dependencies and are slow to run.
They can also be unstable and flaky so they're not always the best option. Layout Tests fits into the category of Unit testing and uses the XC test framework under the hood. Like Unit Tests, they're very fast and stable, it limits dependencies, and you don't need to even run the app, which means you can isolate the views and test them themselves without having the actual app running. Previously there was no good way to make sure views work properly in all different types of situations. Layout Tests helps you to do that.
It also automatically tests a lot for you and validates the layouts of your views with multiple combinations of data and edge cases. There are certain costs to having tests such as maintenance costs, which means keeping them up and running, having your developers maintaining them, development effort to actually create the test in the first place, and the time, effort, and resources needed to actually run the tests over and over. You want to spend the majority of your efforts on the lowest cost and greatest benefit. As you see here in this graph, the lowest cost says Unit Tests and the highest cost being Manual Tests.
As we say, Layout Tests fits into the Unit Tests category in terms of the cost. Manual Tests costs lots of time and effort to run and they're prone to mistakes and misses by human error. UI Automation can be very flaky which, in turn, means there's a very high maintenance cost and any change in app flow requires your test to change. They're also very slow to run, which means it can require more resources to run them continuously. Unit Tests can have a larger development time as they're very low level but they provide very high coverage of your code, they're very quick to run, and they have a very low maintenance cost.
The cost of Layout Tests are essentially the same as Unit Tests, however, as you'll see, it takes much less code to write them so the development effort is much lower. In this video you learned about different categories of tests and how Layout Tests fits into the testing landscape. You've also gotten a glimpse at what makes Layout Tests such a useful testing framework.
- 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