1
00:00:06,250 --> 00:00:10,950
Everybody has it gone this is Caleb with Dev slopes and in this video we're going to keep talking about

2
00:00:10,950 --> 00:00:17,550
you eye testing of course but we're going to go into what happens if you discover a bug in your application.

3
00:00:17,610 --> 00:00:21,670
How can we write a test to ensure that that bug has been squashed.

4
00:00:21,690 --> 00:00:29,350
So pull open your project and we're actually going to go ahead and sort of modify how our project works.

5
00:00:29,670 --> 00:00:36,270
And so I'm going to go into onboarding or interface Fisi rather and make sure OK good.

6
00:00:36,270 --> 00:00:38,300
We don't have anything extra there.

7
00:00:38,310 --> 00:00:41,320
That's exactly what we want then.

8
00:00:41,580 --> 00:00:49,470
We did have an alert VC was presented when we tap the done button but that's not exactly the way I want

9
00:00:49,470 --> 00:00:50,430
to do it.

10
00:00:50,430 --> 00:00:57,360
I'm going to make it so that when the view does appear on interface Visi if the onboarding is not complete

11
00:00:57,360 --> 00:00:59,040
of course we present the onboarding.

12
00:00:59,040 --> 00:01:05,970
But if that's not the case if onboarding is completed we're going to go ahead and create an alert feature.

13
00:01:06,060 --> 00:01:14,700
So let alert the C equals UI alert controller of course give it a title saying I don't know you did

14
00:01:14,700 --> 00:01:15,130
it.

15
00:01:15,150 --> 00:01:22,800
I think we said that before already but yea you made it.

16
00:01:22,910 --> 00:01:28,170
You are the best sort of That'll work.

17
00:01:28,490 --> 00:01:30,780
The style is just going to be an alert.

18
00:01:30,830 --> 00:01:34,040
And then of course we need an action so that we can actually dismiss it.

19
00:01:34,040 --> 00:01:39,370
So Type let action equals UI alert action.

20
00:01:39,890 --> 00:01:41,850
Go ahead and give it a title saying I don't know.

21
00:01:41,870 --> 00:01:46,170
Awesome and a style of default and no handler.

22
00:01:46,220 --> 00:01:47,910
Don't worry about that.

23
00:01:47,960 --> 00:01:55,550
But then all we need to do is type alert Visi add action and pass in our actions so very very cool stuff

24
00:01:55,820 --> 00:02:00,180
that should then present our alert Visi Now if you're thinking wait you forgot something.

25
00:02:00,350 --> 00:02:01,190
Don't worry about it.

26
00:02:01,220 --> 00:02:07,370
I've got it under control I promise what we're going to do is we're simulating basically as if we had

27
00:02:07,370 --> 00:02:12,110
written some code to present an alert Visi but we forgot something.

28
00:02:12,110 --> 00:02:18,110
Therefore introducing a bug into our application it's not going to run as we expect and that's what

29
00:02:18,110 --> 00:02:18,920
a bug is.

30
00:02:18,920 --> 00:02:25,850
So go into your test and we're going to write a test to ensure that our alert view pops up when the

31
00:02:25,850 --> 00:02:27,800
interface UI is showing.

32
00:02:27,800 --> 00:02:30,770
OK when we dismiss our onboarding experience.

33
00:02:30,800 --> 00:02:34,170
So phunk test interface.

34
00:02:34,220 --> 00:02:36,890
VC alert.

35
00:02:36,890 --> 00:02:47,320
We're testing alert view shows when onboarding complete whip's pleat.

36
00:02:47,360 --> 00:02:48,090
All right.

37
00:02:48,170 --> 00:02:55,790
So of course to begin we call app launch to launch our fresh instance of our application and then we

38
00:02:55,790 --> 00:03:01,140
need to go through the onboarding process of swiping left two times then tapping the done button.

39
00:03:01,310 --> 00:03:01,940
OK.

40
00:03:02,360 --> 00:03:07,730
And then what we're going to do is we're going to need to basically create some type of way of checking

41
00:03:07,820 --> 00:03:09,320
if it's displaying.

42
00:03:09,320 --> 00:03:15,140
So we're going to go ahead and actually head into our XCI application extension and create a new variable

43
00:03:15,140 --> 00:03:25,240
called var is displaying alert Visi of type bool and we're going to return alerts.

44
00:03:25,360 --> 00:03:25,690
OK.

45
00:03:25,700 --> 00:03:28,680
And we're going to dive into alerts and find the one with the title.

46
00:03:28,700 --> 00:03:31,580
You did it.

47
00:03:31,580 --> 00:03:33,340
And of course this should be in a constant.

48
00:03:33,350 --> 00:03:39,670
But it's not just because of time and now of course we need to call DOT exists.

49
00:03:39,690 --> 00:03:41,550
Whoops that's not exists.

50
00:03:41,550 --> 00:03:42,670
It exists.

51
00:03:42,770 --> 00:03:48,200
So we're going to check at the end if this alert exists if it showing on the screen ok if it's not.

52
00:03:48,200 --> 00:03:49,930
Of course we know we have a problem.

53
00:03:49,970 --> 00:03:50,810
So go ahead.

54
00:03:51,110 --> 00:03:57,070
We're going to assert false so we're going to go ahead and assert true.

55
00:03:57,090 --> 00:04:07,020
So ex-city assert true that the AP's alert interface which we have here is displaying alert Visi we're

56
00:04:07,020 --> 00:04:09,030
asserting that this is true.

57
00:04:09,060 --> 00:04:12,700
So when we run this test I'm going to build it so our Diamond shows up.

58
00:04:12,840 --> 00:04:18,660
But when we run this test our app should launch we should swipe left twice tap the done button and at

59
00:04:18,660 --> 00:04:20,850
that point that alert is supposed to pop up.

60
00:04:20,850 --> 00:04:22,230
So let's go ahead and run the test.

61
00:04:22,230 --> 00:04:24,090
Let's see how we did.

62
00:04:24,330 --> 00:04:27,250
Of course it's going to hide behind their their rear.

63
00:04:27,300 --> 00:04:28,410
So here's our interface.

64
00:04:28,410 --> 00:04:29,680
Very nice.

65
00:04:29,700 --> 00:04:31,710
It's going to go ahead and build the app.

66
00:04:31,770 --> 00:04:32,850
It's going to launch.

67
00:04:32,910 --> 00:04:37,050
And then of course we're going to swipe left one too.

68
00:04:37,050 --> 00:04:37,710
We're going to tap.

69
00:04:37,710 --> 00:04:38,710
Done.

70
00:04:38,880 --> 00:04:47,430
And our test fails now of course we need to put a little help or message here saying alert D.C. should

71
00:04:47,490 --> 00:04:55,050
show when onboarding dismisses and that's just to remind you what is the point of this test if you don't

72
00:04:55,050 --> 00:04:55,900
remember.

73
00:04:56,190 --> 00:04:57,370
Now what we need to do.

74
00:04:57,450 --> 00:05:01,750
This tells us hey I need to go in and fix my code so that that actually shows up.

75
00:05:01,750 --> 00:05:09,200
So go into interface Visi and oh we forgot to call present alert Visi animated.

76
00:05:09,210 --> 00:05:11,250
True with no completion handler.

77
00:05:11,310 --> 00:05:14,100
We forgot to present it of course it's not showing.

78
00:05:14,100 --> 00:05:21,440
So now if I go back and do my tests and I run it and launch it our test should pass.

79
00:05:21,450 --> 00:05:22,150
OK.

80
00:05:22,350 --> 00:05:27,250
So this is a way that you can use UI testing to verify that certain bugs have been fixed.

81
00:05:27,360 --> 00:05:32,700
And of course in the future if this were to fail you would know hey something is going wrong.

82
00:05:32,880 --> 00:05:35,210
So did you see that the alert popped up right at the end.

83
00:05:35,220 --> 00:05:41,970
Our test now passes because that alert existed on the screen so our bug is now fixed.

84
00:05:41,970 --> 00:05:45,670
Now of course you can do this for all kinds of things.

85
00:05:45,750 --> 00:05:51,180
Let's say that there's a bug in your app where you go through a certain set of steps and then you tap

86
00:05:51,210 --> 00:05:55,760
on a table view cell and it crashes once you think you have fixed that.

87
00:05:55,770 --> 00:05:58,950
You write a test to make sure it's working as expected.

88
00:05:59,010 --> 00:06:05,780
And just so you know to access the access table view cells you can go ahead and type app dot cells that

89
00:06:05,880 --> 00:06:07,620
element bound by.

90
00:06:07,650 --> 00:06:13,770
And that basically allows you to find an element that uses a particular index like a table view cell

91
00:06:13,780 --> 00:06:17,610
so maybe it's an index to where you're having this problem.

92
00:06:17,700 --> 00:06:18,540
You fix it.

93
00:06:18,750 --> 00:06:26,070
And then what you can do is you can call cells that element bound by index to tap and it'll tap that

94
00:06:26,070 --> 00:06:26,670
cell for you.

95
00:06:26,670 --> 00:06:28,010
Very very cool.

96
00:06:28,020 --> 00:06:35,790
Super easy way to test table table views as well as ordinary views and buttons and alerts you can really

97
00:06:35,790 --> 00:06:36,480
test it all.

98
00:06:36,480 --> 00:06:43,560
Now there is something that I have not yet shown you that is very cool but very inconsistent so I recommend

99
00:06:43,620 --> 00:06:44,840
against using it.

100
00:06:45,120 --> 00:06:50,070
But what you can do is basically you can click this little red record button at the bottom.

101
00:06:50,070 --> 00:06:52,250
Now check out what happens when I click on this.

102
00:06:52,350 --> 00:06:58,370
It's going to go ahead and build and launch my app and watch what's going to happen if I tap on this.

103
00:06:58,380 --> 00:07:02,530
It's going to basically record of what I have done in the application.

104
00:07:02,760 --> 00:07:10,440
So I get an instance of X see UI application I go into my particular alert I go into those buttons and

105
00:07:10,440 --> 00:07:12,810
then find the button that is awesome and I tap it.

106
00:07:12,810 --> 00:07:17,940
Now if I click on the View it's going to say hey this is one way to access that view.

107
00:07:17,950 --> 00:07:22,260
I can keep clicking I can move around and it records everything that I do.

108
00:07:22,260 --> 00:07:28,710
However this does not consistently work and it's much better to reliably do this programmatically so

109
00:07:28,710 --> 00:07:30,550
that you don't have these problems.

110
00:07:30,610 --> 00:07:31,210
OK.

111
00:07:31,260 --> 00:07:34,420
It can cause issues so it's better to do it the way that I've taught you.

112
00:07:34,440 --> 00:07:36,900
So let's go ahead we have just introduced a new test.

113
00:07:36,900 --> 00:07:38,240
We've changed our code.

114
00:07:38,250 --> 00:07:41,940
Let's go ahead and let's make sure that our application all tests run.

115
00:07:42,030 --> 00:07:44,940
You can go ahead and either click the diamond at the top here.

116
00:07:45,000 --> 00:07:45,220
OK.

117
00:07:45,240 --> 00:07:47,650
Like I just did like.

118
00:07:47,910 --> 00:07:48,600
Well hold on.

119
00:07:48,620 --> 00:07:49,820
Make me quit this.

120
00:07:49,870 --> 00:07:50,670
I may do it again.

121
00:07:50,670 --> 00:07:51,290
There we go.

122
00:07:51,420 --> 00:07:52,940
Or you can press command.

123
00:07:52,940 --> 00:07:54,380
I that's another way to do it.

124
00:07:54,400 --> 00:07:57,890
So it's going to go ahead and run every single one of our tests.

125
00:07:57,900 --> 00:07:59,640
We will see them all here.

126
00:07:59,640 --> 00:08:00,790
Hopefully they'll pass.

127
00:08:00,840 --> 00:08:05,590
If they don't we know for sure that we need to fix something.

128
00:08:05,640 --> 00:08:06,300
OK.

129
00:08:06,300 --> 00:08:09,060
So the first test goes through it passes second test.

130
00:08:09,060 --> 00:08:12,620
Here we go swipe left swipe left tap done.

131
00:08:12,810 --> 00:08:16,010
And the onboarding does go away so that's perfect.

132
00:08:16,020 --> 00:08:20,730
And now the third Test we're just basically checking to see if our view controller loads properly and

133
00:08:21,030 --> 00:08:21,600
it does.

134
00:08:21,600 --> 00:08:23,290
So this test is now complete.

135
00:08:23,400 --> 00:08:29,910
You now know how to implement tests to verify that certain bug fixes have indeed been fixed and to make

136
00:08:29,910 --> 00:08:31,940
sure that they don't get re-introduced in the future.

137
00:08:31,950 --> 00:08:33,710
This is Kaylyn whatever slopestyle.

138
00:08:33,870 --> 00:08:35,090
Let's head over to the next video.
