Getting your Xcode ready for UI tests

Fabio Soares
XCUITest
Published in
4 min readMar 27, 2021

This is the third in a series of blog posts where I share what Ive learned about XCUITest and how to get started with it.

Before you start

As you may already be aware, creating UI tests for iOS using XCUITest require some hardware.

  • Mac
  • Xcode

Here are my settings for reference, but I've started with a MacBook Air, so basically, if the Mac is not too old, you can probably do it.

The project

I grabbed this project on GitHub of a basic to-do list app https://github.com/KhaHC/SwiftUITodo.

Four screenshots of a simple to-do list application

Step by step from Github to running the test

If you have any questions or need some assistance, check the first 10 minutes of this video on YouTube, where I do the same thing as in the following steps:

Pulling the repo from GitHub

The first thing you have to do is to pull the project to your local machine, so you open it on Xcode and start making changes to it.

This is how you do it:

1 — Open this link https://github.com/KhaHC/SwiftUITodo

2 — Click on the Code dropdown

3 — Select HTTPS and copy the URL

Cloning to your terminal

Once you've copied the URL, open the terminal on your Mac and run the following command.

git clone <url copied from github>

Opening Xcode

Open Xcode and select the project present on the directory you've cloned the repository.

Now let's take a look at what Xcode looks like for this project:

As you can see, there's no UI tests group. Let's create them now :)

Creating the UI Tests target

1 — Click on the SwiftTodo project

2 — Under TARGETS, click on the + button

3 — Choose the UI Testing Bundle template for the new target being created,

4 — Naming the target will automatically be something like AppNameUITests, which is what we want

What was added to the project?

The project now has a new group folder called SwiftUITodoUITests, and inside of it, there's already one test created.

Running the first test

As you can see below, there’s already one basic UI test created. To run it, you have to click on the diamond play button next to the test name.

This is pretty cool as you're already going to see the simulator spinning up for some action.

If the test passes, the diamond becomes green. If it fails, red. See below:

You're all set up!

That's all you need to set up for creating UI tests on Xcode. The next steps are adding actual tests there that will assert the app is functional. But that's enough for today. If you'd like to keep going and create a test, you're welcome to check the next post to see how we can find elements on the screen :)

See you there!

Check my website for more content about testing, mobile, agile and much more! 👇👇👇

--

--