Member-only story
Initialising a view controller from a test using Swift
Testing is important, so we really need to get this right
Testing is extremely important in software, but there are few guides on how you can manipulate a view controller to help you out. This might be just the right guide for you!
Difficulty: Beginner | Easy | Normal | Challenging
Prerequisites:
- Be able to produce a “Hello, World!” iOS application (guide HERE)
- Have some understanding of basic testing in Swift
Terminology
storyboard: A way to graphically lay out the UI in Xcode
unit testing: Software testing where individual units or components of the software is tests
view controller: A view controller is an intermediary between the views it manages and the data of your app
The Setup
Creating a basic view controller
The setup here is simple: create a basic “Hello, World!” style application with a single UILabel
that is centred on the view controller.
Now we need to give the view controller an identifier, that is set the Storyboard ID
to ViewController
(which is set in…