1
00:00:00,830 --> 00:00:05,840
So let's check our coverage for the handlers package and see what kind of test coverage we have right

2
00:00:05,840 --> 00:00:10,880
now, and I want to go to my terminal and the command to do that is really easy.

3
00:00:10,880 --> 00:00:12,740
Go test dash cover.

4
00:00:13,220 --> 00:00:18,530
And that will show me that I've got about seventy nine point two percent of the statements covered in

5
00:00:18,530 --> 00:00:22,080
the package handlers, which is a pretty good percentage, but it should be better.

6
00:00:22,460 --> 00:00:26,930
So let's look at the HTML version of that and I'm going to show you, first of all, how to do it from

7
00:00:26,930 --> 00:00:31,070
the command line and secondly, how to do it from the command line without typing a whole bunch of things

8
00:00:31,070 --> 00:00:32,450
and potentially making lots of errors.

9
00:00:33,170 --> 00:00:35,140
So the command to do that is here.

10
00:00:35,150 --> 00:00:36,260
And this is on Linux.

11
00:00:36,740 --> 00:00:37,260
On Linux.

12
00:00:37,280 --> 00:00:39,530
I can do it as one line or on a Mac.

13
00:00:39,530 --> 00:00:41,870
I can do it as one line on windows.

14
00:00:41,870 --> 00:00:44,510
You have to do it as two separate commands, but they're the same commands.

15
00:00:44,750 --> 00:00:46,760
Go test, test, dash cover.

16
00:00:46,760 --> 00:00:50,690
Profile equals coverage out, which will create a file called coverage out.

17
00:00:51,230 --> 00:00:57,670
And then on Mac and Linux, the double ampersand says if this succeeds, then run the next command.

18
00:00:57,680 --> 00:01:03,530
If it doesn't, then stop and the next command is go to cover dash HTML equals the name of the file.

19
00:01:03,530 --> 00:01:08,010
We created coverage out, so I'll press enter to get this coverage and there it goes.

20
00:01:08,030 --> 00:01:11,410
Fires up my web browser will only have one package to look at.

21
00:01:11,450 --> 00:01:12,530
So here it is.

22
00:01:12,530 --> 00:01:15,320
Things that are Ingrey are not tracked and can be ignored.

23
00:01:15,620 --> 00:01:21,320
Things that are in red are not tested and can't be ignored and things that are in green are good because

24
00:01:21,320 --> 00:01:22,220
we have coverage there.

25
00:01:22,670 --> 00:01:25,030
So we'll just scroll down till we see some red.

26
00:01:25,040 --> 00:01:28,140
Here we are post reservation, so a lot of red in this one.

27
00:01:28,730 --> 00:01:33,800
So the first one says if we can't pass the form printing error in return, I can live with that.

28
00:01:33,980 --> 00:01:35,210
OK, that's not a big deal.

29
00:01:35,930 --> 00:01:40,970
But the next one, if the form is not valid, this never gets executed.

30
00:01:41,000 --> 00:01:43,400
And that's when I actually do want to test.

31
00:01:43,400 --> 00:01:44,270
But not right now.

32
00:01:44,270 --> 00:01:48,110
As I said, the last lecture, we'll do that once we have a means of storing information in the database.

33
00:01:48,350 --> 00:01:49,450
So we'll come back to that one.

34
00:01:49,760 --> 00:01:50,480
Let's keep going.

35
00:01:51,580 --> 00:01:56,960
And down here, if we can't marshal the Jason from this, that's not an issue right now.

36
00:01:57,040 --> 00:01:57,780
That doesn't bother me.

37
00:01:57,780 --> 00:01:58,700
I'm going gonna leave that one alone.

38
00:01:59,590 --> 00:02:00,800
Here's one that does bother me.

39
00:02:01,180 --> 00:02:03,010
This is when reservation summary.

40
00:02:03,050 --> 00:02:04,000
Now, hang on a sec.

41
00:02:04,030 --> 00:02:06,370
Do we even test for reservation summary?

42
00:02:06,400 --> 00:02:07,290
Let's go back and look.

43
00:02:07,870 --> 00:02:09,700
So handler's test.

44
00:02:12,820 --> 00:02:14,440
No, we never even called that one.

45
00:02:14,470 --> 00:02:17,640
Well, there's one we have to add, so we'll do that, not right now.

46
00:02:17,660 --> 00:02:19,360
I'll leave that as an exercise for you right now.

47
00:02:19,360 --> 00:02:21,400
But the next time I'm working on this test, I'll add it.

48
00:02:21,730 --> 00:02:22,950
And you know, just two things here.

49
00:02:23,230 --> 00:02:26,170
The first part of this reservation summary did get cold.

50
00:02:26,440 --> 00:02:31,480
It got cold after we did a successful post or make reservation post.

51
00:02:31,780 --> 00:02:37,270
So this worked and it actually gave us an error, which we didn't even know until we looked at our test

52
00:02:37,270 --> 00:02:37,720
coverage.

53
00:02:37,990 --> 00:02:40,480
And the error was cannot get item from session.

54
00:02:40,490 --> 00:02:47,110
So we'll have to go modify our handlers to handle sessions the same way that we did in our surrender

55
00:02:47,110 --> 00:02:47,560
package.

56
00:02:47,830 --> 00:02:48,910
And we could do that then.

57
00:02:48,910 --> 00:02:52,480
And that will take care of this situation as well, because then we would be able to test for it.

58
00:02:53,110 --> 00:02:53,530
All right.

59
00:02:53,530 --> 00:02:54,660
So that was for that one.

60
00:02:54,910 --> 00:03:00,490
Now, as I said a moment ago, I really don't like typing this long, command this one out.

61
00:03:00,880 --> 00:03:06,130
So what I'm going to do, and this will only work on a Mac or Linux is I'm going to go open a new tab

62
00:03:06,190 --> 00:03:11,020
or go open a new terminal window and I'll go to my home folder, which is right here.

63
00:03:11,290 --> 00:03:18,460
And on a Mac, at least a recent version, you're going to have a file called Z Profile, Dot, dot,

64
00:03:18,460 --> 00:03:19,320
Z profile.

65
00:03:19,330 --> 00:03:20,780
If you don't have one, you could just create it.

66
00:03:20,890 --> 00:03:21,490
I have one.

67
00:03:21,910 --> 00:03:25,840
And here's where I put things that I really don't want to retype.

68
00:03:26,200 --> 00:03:32,200
And I do it using the Syntex alias and I'm just going to say an alias for the command coverage that's

69
00:03:32,200 --> 00:03:32,980
going to equal.

70
00:03:32,980 --> 00:03:35,260
And then I'll paste in that long command.

71
00:03:35,680 --> 00:03:38,800
And once I do this, I then have the ability to go back.

72
00:03:38,830 --> 00:03:42,340
I'll create a new terminal window, go to my Google and projects.

73
00:03:42,340 --> 00:03:46,150
You might have to close your terminal window and reopen it to have it reload, but do that if necessary.

74
00:03:46,990 --> 00:03:52,930
And then I'll go into my bookings folder and then I'll go to say handlers, internal handlers and I

75
00:03:52,930 --> 00:03:58,750
can just write coverage and it will do that for me, which is ever so much easier to type.

76
00:03:59,110 --> 00:04:02,860
That's just a little hint to to point you in the right direction.

77
00:04:03,040 --> 00:04:09,370
Now we can also, of course, look at our coverage in our Brender package so I can just type coverage

78
00:04:09,580 --> 00:04:14,110
or type out that long command or those two commands if you're on windows and we'll give you the same

79
00:04:14,110 --> 00:04:14,390
thing.

80
00:04:14,680 --> 00:04:16,570
So what kind of coverage do we have here again?

81
00:04:16,570 --> 00:04:17,860
Eighty point five percent.

82
00:04:18,040 --> 00:04:21,460
And we can scroll through and see what is tested and what is not.

83
00:04:21,700 --> 00:04:26,230
And as you can see in the vast majority of cases, these are the sorts of things that just don't bother

84
00:04:26,230 --> 00:04:26,370
me.

85
00:04:27,100 --> 00:04:29,890
So up here, again, I'm not too worried about that one.

86
00:04:30,010 --> 00:04:31,300
I'm not too worried about that one.

87
00:04:31,300 --> 00:04:32,770
This one I can actually fix.

88
00:04:33,070 --> 00:04:37,180
It says if app use cash, get the template cash from the app config.

89
00:04:37,330 --> 00:04:43,540
So I could fix that one really easily just by coming back into my render package, which is right here.

90
00:04:43,840 --> 00:04:45,130
Look at my render test.

91
00:04:45,670 --> 00:04:46,470
Where was that.

92
00:04:46,720 --> 00:04:54,190
That is testing for render template so I could find test render template and all I'd have to do is come

93
00:04:54,190 --> 00:05:01,630
down here and set app to be app use cash to be false or true and run the test once and that would cover

94
00:05:01,630 --> 00:05:01,990
that.

95
00:05:01,990 --> 00:05:05,520
So you can you can get closer to 100 percent coverage without much difficulty.

96
00:05:05,920 --> 00:05:10,600
Now, as I said before, I don't really sweat the full one hundred percent test coverage.

97
00:05:10,600 --> 00:05:13,480
As long as I'm covering critical code, I'm happy.

98
00:05:13,480 --> 00:05:15,190
I am not a purist in that respect.

99
00:05:15,250 --> 00:05:19,030
There are purists and I'm not criticizing them in any way, shape or form.

100
00:05:19,330 --> 00:05:24,400
But for things like this, for example, log fatal error, we're going to improve our error handling.

101
00:05:24,760 --> 00:05:27,070
I'm not too concerned about this right now.

102
00:05:27,970 --> 00:05:32,110
Little little catches for errors like that don't concern me too much at this point.

103
00:05:32,110 --> 00:05:36,370
Now, as time goes on and the application becomes more sophisticated, we'll be paying more attention

104
00:05:36,370 --> 00:05:37,180
to things like that.

105
00:05:37,180 --> 00:05:42,070
But I want to write the error handling package code before I bother testing this sort of thing.

106
00:05:42,490 --> 00:05:42,910
All right.

107
00:05:42,940 --> 00:05:44,170
That's enough for this time around.
