Swift UI Test: What Is A Functional Test?

In this lesson

In this lesson, you’ll learn what a functional test is and see how they differ from integration and unit tests. See real functional tests run and how they programmatically run an application and verify the application functionality.

Transcript

Tap on time to skip ahead

00:10

In this lesson, I’m going to talk about functional tests. Functional tests validate the operation, the correct operation of typically an application.

00:21

Here I have an application that I wrote called the LoL Champion Browser. As you can see I can navigate around, I can scroll through all the champions, and then I can tap on specific champions and view the skins that are available for that champion. It’s a very simple application. The functional test is going to focus on the application itself and not the individual components or subsystems.

00:48

Let’s have a look at the functional tests that I wrote to test the application. You’ll notice that a typical functional test looks quite different than other types of tests. Here I have getters, or helper functions, that make it easy to access visual components that are on the screen. I will use these in my test because a functional test only has access to the UI state. It only can see what’s on the screen. That’s one of the things that really nice about functional tests. It’s testing the entire application.

01:23

In the setup function here, you’ll notice that I launch the application. This UI application here is linked to the application that I’m testing, so launch causes it to start up. I have four tests. I have a test that verifies that I can scroll to a specific champion, Ziggs in this case. You’ll notice that the language that I’m using here to interact is unique to the framework that I’m using. Yours may be different depending on the language you’re using. Here I’m going to be able to swipe up and I’m going to continue swiping until I see Ziggs and then my assertion is that the Ziggs cell is visible.

02:03

I have three other tests that I can tap on a champion, Annie in this case, and see the skins. My third test is that I can tap on Annie and scroll through looking for a specific skin. My fourth test is that I can tap on Annie and that I can then tap on the back button and go back to the champion browser.

02:24

Let’s go ahead and run this test. I’m going to head over to the test navigator, click on the test that I want to run, and click this button to run the test. What’s going to happen is the test runner is going to actually launch my application for each test and then exit the application when the test is complete.

02:49

What you’re going to notice is that here in the simulator the application launches and it’s running my first test. The first test, if you recall, is that I can scroll the list of champions until I find the champion named Ziggs. These champions are in alphabetical order so it’s going to take five or six different swipes in order to get there.

03:10

You’ll notice that it runs quite slow. That’s because the test has to wait until the application can accept the events that the test is sending to it. It sends a swipe and then it waits for the application to idle and then it sends another swipe and then it looks for, if you recall, the champion named Ziggs. We’re probably another swipe away and we’re going to find Ziggs. Then the application- There’s Ziggs in the bottom left corner. So that test passed. Then it kills the app, relaunches it and it’s running the second one, that I can tap on Annie and go to the skins browser.

03:49

The third test is now running where I can tap on Annie and scroll through the list of skins and look for a specific skin. It’s looking at the label at the bottom of the screen, and looking for Sweetheart Annie. As soon as it finds Sweetheart Annie that test will be complete and it passes.

04:07

The last test is that it will navigate to a specific champion, and tap the back button and verify that it goes back to the champion browser.

04:17

That concludes the functional test. It’s completely from the perspective of the user interface, not the components or the subsystems.

04:28

The last thing I want to show you here is, if we look at the logs, the fact that the functional tests, only four ran but it took nearly 90 seconds to run those four tests. That’s because the tests are being executed against the user interface. Functional tests generally take a long time. In fact, if you test all aspects of a large application, it could take hours to run your functional tests. You’ll want to run these maybe once a day or just once before you release a new build to your testers.

Additional Info

Register to get access to additional resources and info.