Everybody has it gone this is Caleb with Dev slopes and in this video we're going to keep talking about
you eye testing of course but we're going to go into what happens if you discover a bug in your application.
How can we write a test to ensure that that bug has been squashed.
So pull open your project and we're actually going to go ahead and sort of modify how our project works.
And so I'm going to go into onboarding or interface Fisi rather and make sure OK good.
We don't have anything extra there.
That's exactly what we want then.
We did have an alert VC was presented when we tap the done button but that's not exactly the way I want
to do it.
I'm going to make it so that when the view does appear on interface Visi if the onboarding is not complete
of course we present the onboarding.
But if that's not the case if onboarding is completed we're going to go ahead and create an alert feature.
So let alert the C equals UI alert controller of course give it a title saying I don't know you did
it.
I think we said that before already but yea you made it.
You are the best sort of That'll work.
The style is just going to be an alert.
And then of course we need an action so that we can actually dismiss it.
So Type let action equals UI alert action.
Go ahead and give it a title saying I don't know.
Awesome and a style of default and no handler.
Don't worry about that.
But then all we need to do is type alert Visi add action and pass in our actions so very very cool stuff
that should then present our alert Visi Now if you're thinking wait you forgot something.
Don't worry about it.
I've got it under control I promise what we're going to do is we're simulating basically as if we had
written some code to present an alert Visi but we forgot something.
Therefore introducing a bug into our application it's not going to run as we expect and that's what
a bug is.
So go into your test and we're going to write a test to ensure that our alert view pops up when the
interface UI is showing.
OK when we dismiss our onboarding experience.
So phunk test interface.
VC alert.
We're testing alert view shows when onboarding complete whip's pleat.
All right.
So of course to begin we call app launch to launch our fresh instance of our application and then we
need to go through the onboarding process of swiping left two times then tapping the done button.
OK.
And then what we're going to do is we're going to need to basically create some type of way of checking
if it's displaying.
So we're going to go ahead and actually head into our XCI application extension and create a new variable
called var is displaying alert Visi of type bool and we're going to return alerts.
OK.
And we're going to dive into alerts and find the one with the title.
You did it.
And of course this should be in a constant.
But it's not just because of time and now of course we need to call DOT exists.
Whoops that's not exists.
It exists.
So we're going to check at the end if this alert exists if it showing on the screen ok if it's not.
Of course we know we have a problem.
So go ahead.
We're going to assert false so we're going to go ahead and assert true.
So ex-city assert true that the AP's alert interface which we have here is displaying alert Visi we're
asserting that this is true.
So when we run this test I'm going to build it so our Diamond shows up.
But when we run this test our app should launch we should swipe left twice tap the done button and at
that point that alert is supposed to pop up.
So let's go ahead and run the test.
Let's see how we did.
Of course it's going to hide behind their their rear.
So here's our interface.
Very nice.
It's going to go ahead and build the app.
It's going to launch.
And then of course we're going to swipe left one too.
We're going to tap.
Done.
And our test fails now of course we need to put a little help or message here saying alert D.C. should
show when onboarding dismisses and that's just to remind you what is the point of this test if you don't
remember.
Now what we need to do.
This tells us hey I need to go in and fix my code so that that actually shows up.
So go into interface Visi and oh we forgot to call present alert Visi animated.
True with no completion handler.
We forgot to present it of course it's not showing.
So now if I go back and do my tests and I run it and launch it our test should pass.
OK.
So this is a way that you can use UI testing to verify that certain bugs have been fixed.
And of course in the future if this were to fail you would know hey something is going wrong.
So did you see that the alert popped up right at the end.
Our test now passes because that alert existed on the screen so our bug is now fixed.
Now of course you can do this for all kinds of things.
Let's say that there's a bug in your app where you go through a certain set of steps and then you tap
on a table view cell and it crashes once you think you have fixed that.
You write a test to make sure it's working as expected.
And just so you know to access the access table view cells you can go ahead and type app dot cells that
element bound by.
And that basically allows you to find an element that uses a particular index like a table view cell
so maybe it's an index to where you're having this problem.
You fix it.
And then what you can do is you can call cells that element bound by index to tap and it'll tap that
cell for you.
Very very cool.
Super easy way to test table table views as well as ordinary views and buttons and alerts you can really
test it all.
Now there is something that I have not yet shown you that is very cool but very inconsistent so I recommend
against using it.
But what you can do is basically you can click this little red record button at the bottom.
Now check out what happens when I click on this.
It's going to go ahead and build and launch my app and watch what's going to happen if I tap on this.
It's going to basically record of what I have done in the application.
So I get an instance of X see UI application I go into my particular alert I go into those buttons and
then find the button that is awesome and I tap it.
Now if I click on the View it's going to say hey this is one way to access that view.
I can keep clicking I can move around and it records everything that I do.
However this does not consistently work and it's much better to reliably do this programmatically so
that you don't have these problems.
OK.
It can cause issues so it's better to do it the way that I've taught you.
So let's go ahead we have just introduced a new test.
We've changed our code.
Let's go ahead and let's make sure that our application all tests run.
You can go ahead and either click the diamond at the top here.
OK.
Like I just did like.
Well hold on.
Make me quit this.
I may do it again.
There we go.
Or you can press command.
I that's another way to do it.
So it's going to go ahead and run every single one of our tests.
We will see them all here.
Hopefully they'll pass.
If they don't we know for sure that we need to fix something.
OK.
So the first test goes through it passes second test.
Here we go swipe left swipe left tap done.
And the onboarding does go away so that's perfect.
And now the third Test we're just basically checking to see if our view controller loads properly and
it does.
So this test is now complete.
You now know how to implement tests to verify that certain bug fixes have indeed been fixed and to make
sure that they don't get re-introduced in the future.
This is Kaylyn whatever slopestyle.
Let's head over to the next video.