How to test LaunchScreen in iOS

Issue #249

Making splash screen with LaunchScreen.storyboard is now the default way to do in iOS. Testing it with UITests is a bit tricky as this screen is showed the system, and if we test that, we are just testing the system.

What we should test is the content we put in the LaunchScreen storyboard. Is it showing correctly on different screen sizes? Is it missing any texts or images?

One way to test that is via Unit Test. LaunchScreen storyboard always come with 1 UIViewController configured as an initial view controller

1
2
3
4
5
6
7
8
9
10
11
12
class LauncScreenTests: XCTestCase {
func testLaunchScreen() {
let launchScreen = UIStoryboard(name: "LaunchScreen", bundle: nil)
let viewController = launchScreen.instantiateInitialViewController()!

let label = viewController.view.subviews.compactMap({ $0 as? UILabel }).first!
XCTAssertEqual(label.text, "Welcome to my app")

let imageView = viewController.view.subviews.compactMap({ $0 as? UIImageView }).first!
XCTAssertNotNil(imageView.image)
}
}

Comments

You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.