Thursday, November 30, 2017
Friday, November 10, 2017
Get started with UI Tests to automate User Interface tests in iOS 9
First, you’ll have to create a new target for the UI Tests:
Under the Test section, select the Cocoa Touch UI Testing Bundle:
Now open the newly created Project_UI_Tests.swift file in your Project UI Tests folder. On the bottom you have an empty method called testExample. Focus the cursor there and click on the red record button on the bottom.
This will launch your app. You can now tap around and interact with your application. When you’re finished, click the red button again.
The generated code will look similar to this. I already added some example XCTAsserts between the generated lines. You can now already run the tests in Xcode using CMD+ U. This will run both your unit tests and your UI Tests.
You could now already run the tests using the CLI without any further modification, but we want to have the UI Tests in a separate scheme. Click on your scheme and select New Scheme.
Select the newly created UI Test target and confirm.
If you plan on executing the tests on a CI-server, make sure the newly created scheme has the Shared option enabled. Click on your scheme and choose Manage Schemes to open the dialog.
Launch the tests from the CLI
It’s important to also define the version of Xcode to use, in our case that’s the latest beta:
You can even make the beta version your new default by running
Example output when running UI Tests from the terminal:
No extra work needed, you get screenshots for free. By appending the derivedDataPath option to your command, you tell Xcode where to store the test results including the generated screenshots.
Xcode will automatically generate screenshots for each test action. For more information about the generated data, take a look at this writeup by Michele.
To create screenshots in all languages and in all device types, you need a tool likesnapshot. snapshot still uses UI Automation, which is now deprecated.
I’m currently working on a new version of snapshot to make use of the new UI Tests features. This enables snapshot to show even more detailed results and error messages if something goes wrong. I’m really excited about this change 👍
Update: snapshot now uses UI Tests to generate screenshots and the HTML summary for all languages and devices.
Homebrew is the most popular package manager for Mac OS X. Homebrew Cask extends Homebrew with support for quickly installing Mac applications like Google Chrome, VLC, and more. No more dragging and dropping applications!
This is an easy way to install Mac terminal utilities and graphical apps. It’s a bit like Chocolatey or OneGet on Windows, or the package managers included with Linux. It’s even a way to install many of the useful apps that aren’t in the Mac App Store.
Homebrew is a package manager designed for installing UNIX tools and other open-source applications on Mac OS X. It will quickly download and install them, compiling them from source. Homebrew Cask extends Homebrew with support for installing binary apps — the kind you normally drag to your Applications folder from DMG files.
Install Homebrew and Homebrew Cask
First, you’ll need the command-line tools for Xcode installed. On a modern Mac OS X system, you can install these just by running the following command in a Terminal window. You could also install the full Xcode application from Apple, if you prefer — but that takes up more space on your Mac and isn’t necessary.
Next, install Homebrew. You can just open a Terminal window, copy-paste the following command, and press Enter:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
This script informs you what it will do. Press Enter and then provide your password to install it. By default, it installs Homebrew so you can use the brew command without typing the sudo command and providing your password.
Run the following command once you’re done to ensure Homebrew is installed and working properly:
Once you’re done, run the following command to install Homebrew Cask. It uses Homebrew to install Cask:
brew install caskroom/cask/brew-cask
Install Graphical Apps With Homebrew Cask
Now you can get started installing those graphical apps you want. This involves some very simple commands. To search for one, use the following command:
brew cask search name
To install an app, run the following command. Homebrew Cask will automatically download it, extract the app, and install it to your Applications folder.
brew cask install name
To uninstall an app with Homebrew Cask, run the following command:
brew cask uninstall name
Install Open-source Utilities With Homebrew
The Homebrew command is the underlying package manager that installs all those UNIX and open-source utilities you might want. It’s the easiest way to install them on Mac OS X, just as it is on Linux. Like Homebrew Cask, it uses simple commands.
To search for a utility:
brew search name
To download and install that package:
brew install name
To remove that package from your system later:
brew remove name
For more details on using these commands, read the Homebrew Cask Usage guide or the Homebrew brew command manual on their official websites. Not every graphical application or Unix utility you’re looking for will be available, but most of them probably will be.
Unfortunately, there’s no graphical user interface for Homebrew Cask. This is a shame, because — while we geeks love easy terminal utilities — many people could benefit from easy software installation on Mac OS X. They can avoid all the downloading DMG files and clicking around. And, since Mac OS X is now home to Windows-style installer crapware, Homebrew Cask is a way around that.