1

00:00:00,890  -->  00:00:07,860
In the last lesson we learn how to use a debugger in this lesson we will use debugger to fix any issue

2

00:00:08,700  -->  00:00:09,920
in the process.

3

00:00:09,970  -->  00:00:15,530
We're going to learn a couple of things that people learn how to write unit tests using unit.

4

00:00:15,990  -->  00:00:21,810
And we also look at another cool feature of Eclipse debugger to debug the issue.

5

00:00:22,860  -->  00:00:27,130
We want to ensure that the programs we write work correctly.

6

00:00:27,180  -->  00:00:34,740
Some developers rely only on using system not older print statements to verify program correctness but

7

00:00:34,740  -->  00:00:38,260
doing this is really low tech and is very time consuming.

8

00:00:38,670  -->  00:00:43,260
You would have to repeat the process every time some logic is changed.

9

00:00:43,260  -->  00:00:50,340
Similarly you cannot just rely only on using a debugger debugger should mainly be used to identify the

10

00:00:50,460  -->  00:00:51,710
exact cause.

11

00:00:51,810  -->  00:00:54,280
Once we are on that issue.

12

00:00:55,070  -->  00:01:00,270
So the best runtime solution is to use automated uniqueness.

13

00:01:00,270  -->  00:01:04,980
The benefit is that they are automated Arnalds also repeatable illness.

14

00:01:05,320  -->  00:01:12,330
These does ensure that any new changes do not break the system so we can say that the main benefit is

15

00:01:12,600  -->  00:01:16,640
program correctness at all points of times.

16

00:01:16,940  -->  00:01:22,590
With that we can feel confident about our code and sleep peacefully knowing that we are in good shape

17

00:01:22,590  -->  00:01:23,460
.

18

00:01:23,460  -->  00:01:27,670
I'm sure you would agree that this last benefit is really important.

19

00:01:28,440  -->  00:01:34,890
G-Unit is a popular open source framework that allows us to write automated uniqueness for Djala programs

20

00:01:35,780  -->  00:01:42,360
that typically use the best individual unit like methods and Gagin a dot org is the official website

21

00:01:42,390  -->  00:01:43,790
of G-Unit.

22

00:01:44,490  -->  00:01:51,210
It was originally written by goingback Eric Gama who are well-known authors and have written some classics

23

00:01:51,360  -->  00:01:57,900
and software engineering feat and Jaman it is well integrated into eclipse.

24

00:01:57,900  -->  00:02:04,470
Writing a G-Unit best on a desk is as it is referred to in what setting up method input.

25

00:02:04,650  -->  00:02:10,950
Then executing the method with the input and finally testing the actual output with the expected value

26

00:02:10,970  -->  00:02:11,580
.

27

00:02:12,180  -->  00:02:13,230
So let's get started.

28

00:02:13,230  -->  00:02:17,500
Underwrite a unit task is Villatoro lot of a debugger.

29

00:02:17,590  -->  00:02:23,210
Some real work before writing our first unit test case.

30

00:02:23,220  -->  00:02:28,980
Let's look at some new code that has been introduced first as a department class which is a new class

31

00:02:29,220  -->  00:02:34,530
and it has an instance variable called name which represents the department name.

32

00:02:34,860  -->  00:02:42,130
It comes along with a getter and a setter and it is initialized in this constructor course class husbanded

33

00:02:42,150  -->  00:02:43,990
and couple of lessons ago.

34

00:02:45,120  -->  00:02:50,560
A new way that will call Department has been introduced here which is of pipe Department OK and the

35

00:02:50,550  -->  00:02:54,290
department variable is initialized in the constructor or here.

36

00:02:54,780  -->  00:03:01,980
So that department name is a new parameter Department is initialized only if the department name is

37

00:03:01,980  -->  00:03:02,980
not equal to null.

38

00:03:03,150  -->  00:03:09,410
So if it happens to be null then the department variable will also be null and there is also a getter

39

00:03:09,410  -->  00:03:16,800
for the department ready next to that class a new method has been added call and roll.

40

00:03:16,950  -->  00:03:19,680
It allows a student to enroll in a new course.

41

00:03:19,710  -->  00:03:21,990
So courses a parameter here.

42

00:03:22,230  -->  00:03:28,590
And if this method is invoked on a student instance it means that student is trying to add a new course

43

00:03:29,160  -->  00:03:34,920
and a student is allowed to are only a limited number of courses on all the courses that are added are

44

00:03:34,920  -->  00:03:39,730
stored and this data structure and road courses which is an idealist.

45

00:03:39,760  -->  00:03:40,910
And here is the limit.

46

00:03:40,920  -->  00:03:44,820
So we are checking that the student is not enrolling more than this limit.

47

00:03:45,030  -->  00:03:50,410
OK so it is course underscore and underscore Lamech which is a static variable and is initialized with

48

00:03:50,560  -->  00:03:51,680
a rally tree.

49

00:03:51,930  -->  00:03:59,160
On this method invokes this print method print and road courses which all it does is simply iterates

50

00:03:59,220  -->  00:04:05,020
over the root causes and Bentz all the courses that the student has registered for.

51

00:04:05,280  -->  00:04:13,210
So it prints the course name under department name says ghost or department Daut get name on the result

52

00:04:13,230  -->  00:04:19,320
or get her far enrolled course this variable which is the RL list which is here which is created here

53

00:04:19,320  -->  00:04:20,170
.

54

00:04:20,300  -->  00:04:26,060
Don't worry about this generics related BACS since generics is not yet covered.

55

00:04:26,070  -->  00:04:31,520
Other than that I want to just refactor just rename the student test class.

56

00:04:31,950  -->  00:04:37,900
Let's go here to refactor rename it to student test drive.

57

00:04:39,780  -->  00:04:41,690
Let's just do this next.

58

00:04:42,000  -->  00:04:42,800
Finish.

59

00:04:43,050  -->  00:04:47,060
So that's how you rename it class going to refactor under your name.

60

00:04:47,070  -->  00:04:52,560
The reason we want to rename it is because the ESC is that we are going to write in a minute will be

61

00:04:52,560  -->  00:04:53,890
named the student test.

62

00:04:53,900  -->  00:04:56,450
That's because that's the regular convention.

63

00:04:56,520  -->  00:05:02,430
So if we want to test anything in student then the task is a rewrite by convention has to be student

64

00:05:02,430  -->  00:05:02,930
dust.

65

00:05:02,970  -->  00:05:06,060
OK it's not a requirement but just a convention.

66

00:05:06,060  -->  00:05:13,480
That's the reason we are renaming it to student best driver it should be obvious that much of dusting

67

00:05:13,480  -->  00:05:17,700
happens and development environment as opposed to a production environment.

68

00:05:18,120  -->  00:05:24,290
That's because in development and Rutman code is being actively dolar and that is called POBox.

69

00:05:24,640  -->  00:05:30,040
Testing would help in identifying and fixing those bucks on production.

70

00:05:30,040  -->  00:05:32,720
You would expect to be near-perfect.

71

00:05:32,850  -->  00:05:35,290
There is no need for any best guesses.

72

00:05:35,360  -->  00:05:37,200
Mortars are running Vasquez's.

73

00:05:37,330  -->  00:05:43,610
We're also Edam system resources as to how to execute the code they are testing.

74

00:05:43,610  -->  00:05:50,200
So typically real code that needs to be deployed is kept separately from Vasquez's when time comes for

75

00:05:50,200  -->  00:05:50,980
deployment.

76

00:05:51,070  -->  00:05:55,280
Only the real code is deployed or not the task is this.

77

00:05:55,330  -->  00:06:00,600
So let's also follow the same practice and create what gets a subsidy.

78

00:06:00,610  -->  00:06:02,670
Let me just minimize this.

79

00:06:03,250  -->  00:06:07,530
Let's go here into the project and let's head new.

80

00:06:07,750  -->  00:06:15,840
To create a news source folder let's just call it best because we are creating test cases.

81

00:06:15,870  -->  00:06:21,910
Now let's use the same package name here because we are going robustus this class student writing a

82

00:06:21,910  -->  00:06:28,330
test case for that and it need not be the same package name but convention is to use the same package

83

00:06:28,330  -->  00:06:30,050
name as the class being tested.

84

00:06:30,070  -->  00:06:34,460
So let's just go ahead sip package.

85

00:06:34,970  -->  00:06:36,690
It's the same one.

86

00:06:36,730  -->  00:06:39,980
Now let's just go ahead and create our unit desk.

87

00:06:40,000  -->  00:06:50,020
So go into new year after I quicken her G-Unit desk guess it's just call it call it a student test because

88

00:06:50,020  -->  00:06:53,860
we're creating a test case for a student and that needs to be the name on the package.

89

00:06:53,860  -->  00:07:02,980
Here is a package name on class under test would be the Student class no hit next.

90

00:07:03,550  -->  00:07:08,680
And it was all the methods in the Student class and we want to create a test case for this method.

91

00:07:08,860  -->  00:07:13,840
Also shows the math that's an object class because Object class is the superclass.

92

00:07:13,900  -->  00:07:17,740
So this is the only method that we want to test had finished.

93

00:07:18,070  -->  00:07:25,210
It says are G-Unit for a library to go Billy-Bob because it's not yet added but let's do it later in

94

00:07:25,210  -->  00:07:28,900
a bit just from the best guess that gets created.

95

00:07:28,890  -->  00:07:30,450
We'll see how that can be done.

96

00:07:30,730  -->  00:07:31,420
OK.

97

00:07:31,810  -->  00:07:37,030
So this is the test case that God created automatically and as expected it shows completion errors because

98

00:07:37,030  -->  00:07:39,190
their uniform is not in the classpath.

99

00:07:39,310  -->  00:07:41,090
So we need to add that library.

100

00:07:41,110  -->  00:07:45,000
So let's just call it what it says gives three quick fixes.

101

00:07:45,000  -->  00:07:51,460
It says you can add this unit for library book I believe but it's true that I know you can see the compression

102

00:07:51,460  -->  00:07:57,850
errors Mandvi and it got added here so that our libraries in our other JRD under G-Unit for guess if

103

00:07:57,850  -->  00:08:02,360
you ever want to remote just right click go to belly button Heydari Movember.

104

00:08:03,100  -->  00:08:10,270
OK now here are the matter that needs to start is and roar and you can see that G-Unit has created this

105

00:08:10,260  -->  00:08:17,050
desk is called best Android so it always uses this kind of a naming convention best followed by the

106

00:08:17,410  -->  00:08:21,550
Mathare the method name that GHI that's going to be tested on.

107

00:08:21,580  -->  00:08:23,760
Here is an on additions and additions.

108

00:08:23,800  -->  00:08:31,360
We did not cover unpropitious yet but it's simply a moderator data and it does G-Unit that this is this

109

00:08:31,360  -->  00:08:33,040
particular method is a best guess.

110

00:08:33,070  -->  00:08:40,090
So if you read this and you were audited SR as an addition as G-Unit that the method to which it is

111

00:08:40,090  -->  00:08:45,240
attached can be run as a test case to run them at their G-Unit first constructs a fresh instance of

112

00:08:45,250  -->  00:08:49,550
the class which is the student class this class then invokes the unaudited matter.

113

00:08:49,620  -->  00:08:54,390
Any exceptions thrown by that test will be reported as a failure if no exceptions are thrown that Destin's

114

00:08:54,400  -->  00:08:55,970
is used to have succeeded.

115

00:08:56,120  -->  00:08:58,680
Maybe look at both failure and succeeded.

116

00:08:58,840  -->  00:09:01,350
And it should be clear and it should be clear to you.

117

00:09:01,570  -->  00:09:08,320
Now here there is this matter called fail which is a static method in a class called assert which is

118

00:09:08,320  -->  00:09:09,960
being imported here.

119

00:09:10,170  -->  00:09:10,700
OK.

120

00:09:10,780  -->  00:09:12,670
We haven't had Biscoe static imports.

121

00:09:12,700  -->  00:09:17,800
If possible I might include a separate lesson for that but I think this discussion should suffice too

122

00:09:17,800  -->  00:09:18,210
.

123

00:09:18,220  -->  00:09:23,500
So let's start taking borders as it imports all the static members like the static field from the static

124

00:09:23,500  -->  00:09:25,810
methods in a particular class.

125

00:09:25,840  -->  00:09:27,550
So I don't think that this is a package.

126

00:09:27,580  -->  00:09:31,390
It's a class actually and we are importing all the static members from it.

127

00:09:31,540  -->  00:09:37,500
And the advantage of that is you don't have to qualified the static member using the class name you

128

00:09:37,500  -->  00:09:39,420
don't have to do a search dogface.

129

00:09:39,460  -->  00:09:44,680
You can invoke it directly just like invoking any method in the same class.

130

00:09:44,670  -->  00:09:45,090
OK.

131

00:09:45,250  -->  00:09:51,190
So that that's the I'd want it you don't have to qualify it using the class me but you must use it sparingly

132

00:09:51,180  -->  00:09:51,340
.

133

00:09:51,360  -->  00:09:55,330
That's because it can confuse your readers if you use it excessively.

134

00:09:55,480  -->  00:10:01,090
It might confuse the readers of your code or you yourself because it's not clear whether you're invoking

135

00:10:01,090  -->  00:10:07,480
a method in this class or if you are working a method within this class.

136

00:10:07,620  -->  00:10:12,120
OK so use it sparingly and just go ahead and run this.

137

00:10:12,490  -->  00:10:15,600
And it says of one failure.

138

00:10:15,630  -->  00:10:19,740
The reason is because this method is responsible for that.

139

00:10:19,890  -->  00:10:25,720
What this method means is it just means that the best guess is incomplete and new to selling the dodo

140

00:10:25,780  -->  00:10:29,930
bird that you need to implement it sooner it's just be some real code here.

141

00:10:30,000  -->  00:10:34,410
I do a control issue f on what exactly are we testing here.

142

00:10:34,450  -->  00:10:43,260
We are testing to ensure that student is not allowed to enroll in more than that the limit the max limit

143

00:10:43,380  -->  00:10:44,350
number of courses.

144

00:10:44,380  -->  00:10:44,670
OK.

145

00:10:44,680  -->  00:10:48,560
So should a student should enroll only in three courses.

146

00:10:48,850  -->  00:10:52,070
So here is how we set up that task is sort of the input.

147

00:10:52,180  -->  00:10:57,930
So we're creating a student instance here first then we are creating a course instance instance and

148

00:10:57,940  -->  00:11:03,670
passing for other department and we are doing the method execution.

149

00:11:03,730  -->  00:11:09,320
So we are in walking the enrollment third installment by passing discourse one variable which is a course

150

00:11:09,370  -->  00:11:10,340
which is of course.

151

00:11:10,650  -->  00:11:15,790
And finally we are testing the output though the enrollment there is not retaining anything.

152

00:11:15,970  -->  00:11:17,380
We are testing.

153

00:11:17,440  -->  00:11:22,610
There is a change of speed when when this method is getting executed and we are checking that.

154

00:11:22,620  -->  00:11:24,050
So what are we dusting here.

155

00:11:24,060  -->  00:11:27,970
We're getting all the courses that the student has enrolled in.

156

00:11:27,970  -->  00:11:33,640
So we are sort of credence on our list with all the courses that the student has enrolled and we are

157

00:11:33,660  -->  00:11:39,940
calling the size method of idlest undertows how many courses the student has registered and it should

158

00:11:39,940  -->  00:11:42,610
be less than the limit that we have.

159

00:11:42,650  -->  00:11:43,320
OK.

160

00:11:43,330  -->  00:11:50,050
And guess if if it is less we are good about but if it exceeds then it means something wrong has happened

161

00:11:50,050  -->  00:11:50,080
.

162

00:11:50,100  -->  00:11:57,280
Logic has been written in a wrong way and G-Unit would throw an error on it or spread this message.

163

00:11:57,320  -->  00:12:00,170
Enrollment limit exceeded should never happen.

164

00:12:00,270  -->  00:12:02,820
So and then we are adding some more courses here.

165

00:12:03,390  -->  00:12:04,320
Nothing more than that.

166

00:12:04,330  -->  00:12:07,440
So as Drew is also a method in the class.

167

00:12:07,620  -->  00:12:10,890
So let's just go ahead and run this.

168

00:12:11,320  -->  00:12:14,290
You know it says one error failure zero.

169

00:12:14,290  -->  00:12:20,410
So what is an error what is a failure or is basically some kind of an internal error like a null pointer

170

00:12:20,400  -->  00:12:21,990
exception or something like that.

171

00:12:22,120  -->  00:12:28,570
And if failure is something like that's where you're testing some expected value with the actual or

172

00:12:28,930  -->  00:12:35,740
they are not meeting that is expected is different from the actual and then Junod were throw we would

173

00:12:35,740  -->  00:12:37,790
say that a failure has happened.

174

00:12:38,050  -->  00:12:39,200
So what is the error here.

175

00:12:39,220  -->  00:12:44,010
It says null pointer exception which means that something went wrong.

176

00:12:44,050  -->  00:12:48,460
This is the stack trace and it's just DoubleClick and debug it using over debugger.

177

00:12:48,460  -->  00:12:49,810
So let's go here.

178

00:12:49,990  -->  00:12:52,950
This is a matter where some issue has come up.

179

00:12:53,160  -->  00:13:01,800
So let's just set up our break point here and let's call our friend debugger tool and test Java.

180

00:13:02,130  -->  00:13:03,790
And here it stops.

181

00:13:03,790  -->  00:13:10,560
So the issue is null pointer exception so we don't know whether it is cause is null courses here or

182

00:13:10,570  -->  00:13:14,180
with of course don't get Department we are displaying the department name.

183

00:13:14,230  -->  00:13:18,040
So we are saying get Department we don't know if this is not.

184

00:13:18,570  -->  00:13:19,600
So one of them is null.

185

00:13:19,620  -->  00:13:25,590
But in this case it's obviously you know if you holler over course we know that it is not.

186

00:13:25,600  -->  00:13:32,840
No but it could also be know what caused our get Department is obviously not here.

187

00:13:33,040  -->  00:13:38,560
So but let's just pretend that we don't know and let's try to figure that out.

188

00:13:38,560  -->  00:13:44,950
So for that what you can do is we can use a new feature of Eclipse guard expeditions where we were test

189

00:13:45,070  -->  00:13:49,920
expression expression can be coarse expression can be course not good department.

190

00:13:49,960  -->  00:13:55,860
So let's just see if any of these expressions is not sort of just going to window which says sure you

191

00:13:56,980  -->  00:13:58,440
hit exhibition's here.

192

00:13:58,470  -->  00:14:01,030
Yes and it's an expression.

193

00:14:01,090  -->  00:14:07,930
It's just called this course which is an expression here and it has some value which means it does not

194

00:14:07,920  -->  00:14:08,270
know.

195

00:14:08,290  -->  00:14:12,510
So that's not that's not an issue with that.

196

00:14:12,510  -->  00:14:17,330
Another way to add exhibition is just copy this on our new exhibition and listed there.

197

00:14:17,320  -->  00:14:20,340
Or you can also do this you can head control shift.

198

00:14:20,530  -->  00:14:24,780
I mean you do that it opens this pop up and it shows the value.

199

00:14:24,790  -->  00:14:30,680
Now if you want this to show up in that exhibitions you hit Control shift I one more time.

200

00:14:30,850  -->  00:14:31,880
And there you go.

201

00:14:31,970  -->  00:14:32,670
Here the value.

202

00:14:32,710  -->  00:14:34,620
So that's the null value.

203

00:14:34,620  -->  00:14:41,200
So when we are in we'll can get name on this Nuddle it is giving us a null pointer exception.

204

00:14:41,200  -->  00:14:46,300
So we need to fix that and for that we need this kind of a statement.

205

00:14:46,330  -->  00:14:53,080
So you would execute this system not out statement only if Gore's Target department does not equate

206

00:14:53,080  -->  00:14:53,540
to none.

207

00:14:53,560  -->  00:14:56,520
So that's the fix that we need to have.

208

00:14:56,810  -->  00:14:57,080
OK.

209

00:14:57,300  -->  00:15:03,700
But what happened when I just we just added this court thought stop in the same debug session we did

210

00:15:03,700  -->  00:15:06,070
not stop the debug session.

211

00:15:06,220  -->  00:15:11,810
So we have just added on the fly we have added our fix on the fly.

212

00:15:12,120  -->  00:15:17,150
And when we saved it controlled went back to the first day first line of the matter.

213

00:15:17,270  -->  00:15:17,940
OK.

214

00:15:18,150  -->  00:15:19,660
Now we can test it right.

215

00:15:19,680  -->  00:15:26,550
So let's just hit her as you just hit her is the industry on it's just hit or is you

216

00:15:31,120  -->  00:15:32,140
going to G-Unit.

217

00:15:32,130  -->  00:15:37,070
We actually have some other failure but this one is gone.

218

00:15:37,160  -->  00:15:40,850
This area is not that it was something else we will figure that out.

219

00:15:40,990  -->  00:15:48,280
But the main thing as exhibitions are very useful when you have a chain of in locations like caused

220

00:15:48,300  -->  00:15:52,990
or get Department thought let's say something else get something DOD get something.

221

00:15:52,990  -->  00:15:59,460
And that is you would you know if there is a null pointer exception you don't know which is which subexpression

222

00:15:59,470  -->  00:16:00,740
is good but is not.

223

00:16:00,930  -->  00:16:08,160
So you would you know an inexperienced Dolapo would keep printing each of the invocations here using

224

00:16:08,150  -->  00:16:10,320
a system not out and we're trying to figure it out.

225

00:16:10,500  -->  00:16:13,360
But the thing you can do is you can always do this.

226

00:16:13,430  -->  00:16:17,860
UNDERSHAFT I know whether it's down whether it's in Larnaca.

227

00:16:17,980  -->  00:16:23,470
Now if it does not matter then you would expand it and you will try for this.

228

00:16:23,470  -->  00:16:30,700
So there are a chain of indications chain off in locations like if you a call this has a or b b c c

229

00:16:30,730  -->  00:16:31,400
or d.

230

00:16:31,410  -->  00:16:36,240
So if you have a chain of invocations then exhibition's who would be perfect.

231

00:16:36,390  -->  00:16:43,170
OK now let's just go up go back to our unit.

232

00:16:43,380  -->  00:16:45,410
Let's see what the issue is.

233

00:16:45,490  -->  00:16:48,830
It says best Andrle.

234

00:16:49,400  -->  00:16:55,300
It's a failure which means that the expected value did not meet the actual value.

235

00:16:55,300  -->  00:16:58,360
So let's just click on that and here it is.

236

00:16:58,360  -->  00:17:01,930
And the last line there is some issue.

237

00:17:02,020  -->  00:17:06,310
The issue is let's just going to unroll matter here.

238

00:17:06,580  -->  00:17:08,690
Let's not use our debugger.

239

00:17:09,220  -->  00:17:15,450
So here the issue is it says less than or equal to cause and No-Limit.

240

00:17:15,580  -->  00:17:18,420
This should have been less than similar.

241

00:17:19,030  -->  00:17:24,450
Because of that it was showing an error even when the fault course was added.

242

00:17:24,450  -->  00:17:27,850
So if you go back to student dust.

243

00:17:27,930  -->  00:17:35,680
So I suppose the first course that got added and the logic shouldn't have allowed us to added and allowed

244

00:17:35,670  -->  00:17:44,210
us to add on so when we try to test it it failed and it helped us to fix this logic issue.

245

00:17:44,260  -->  00:17:45,150
So that's about it.

246

00:17:45,150  -->  00:17:46,310
That's all I wanted to show.

247

00:17:46,330  -->  00:17:53,390
So we looked at how to create a test case and we also looked at the new expeditions feature of debugger

248

00:17:53,430  -->  00:18:00,480
which is very useful when you have a chain of implications and we need to see some value more there

249

00:18:00,490  -->  00:18:01,360
.

250

00:18:01,410  -->  00:18:03,010
So that's about it.
