1
00:00:04,390 --> 00:00:11,230
Another common stage that you may encounter when building S.I pipelines is the unit stage or the unit's

2
00:00:11,230 --> 00:00:11,650
job?

3
00:00:12,530 --> 00:00:13,840
First, what does the unit test?

4
00:00:14,560 --> 00:00:20,460
Unit tests are responsible for testing only single units of code, typically only one class.

5
00:00:20,920 --> 00:00:24,610
The execution time is very fast and they give instant feedback.

6
00:00:25,420 --> 00:00:30,280
A common concept that you'll hear when discussing testing is the so-called testing pyramid.

7
00:00:30,520 --> 00:00:37,090
It takes different forms and shapes, but always at the bottom of the test pyramid you will find the

8
00:00:37,090 --> 00:00:38,050
unit test.

9
00:00:38,680 --> 00:00:41,920
The reason why they are there is the reason I have specified before.

10
00:00:42,100 --> 00:00:43,510
They run very, very fast.

11
00:00:43,630 --> 00:00:45,280
They don't have a lot of preconditions.

12
00:00:45,280 --> 00:00:48,580
They don't need the entire application and they are quite cheap.

13
00:00:48,580 --> 00:00:51,100
They are easy to write, easy to execute.

14
00:00:51,460 --> 00:00:55,840
So overall, the cost of having unit tests is very, very good.

15
00:00:56,880 --> 00:01:01,640
Now, they are not the only kind of test that we can have in our application, just because the unit

16
00:01:01,640 --> 00:01:04,500
tests to run doesn't mean that the entire application works.

17
00:01:05,069 --> 00:01:11,070
But they are a very important level and they are present in practically any continuous integration pipeline.

18
00:01:12,640 --> 00:01:14,530
Let me give you an example from the application.

19
00:01:15,650 --> 00:01:22,190
Kareem Posman, if I go to the statistics folder, I'll be able to get to the average fleet age.

20
00:01:23,390 --> 00:01:30,020
Now, this is something that is computed inside a code, which means that there is a Java class which

21
00:01:30,020 --> 00:01:35,810
will go over all the vehicles that are in the database and you can view them here.

22
00:01:37,060 --> 00:01:41,590
Will it take to build here and will do an average with this building?

23
00:01:43,380 --> 00:01:51,990
Looking at a code, this can be found in source main Java Services Fleet Statistics Service.

24
00:01:52,910 --> 00:01:59,060
And even if you're not too much into Java, you can easily see how this works, it goes over all the

25
00:01:59,060 --> 00:02:05,150
cars and it all use the average function to get an average from the builder and will give this information

26
00:02:05,150 --> 00:02:05,450
back.

27
00:02:06,110 --> 00:02:11,930
Now, this code may or may not work, so we're not really sure if we need to add additional things to

28
00:02:11,930 --> 00:02:15,630
the code, then it may break out of things that previously used to work.

29
00:02:15,830 --> 00:02:22,760
So for that reason, we always write unit tests which test at this particular class or this particular

30
00:02:22,970 --> 00:02:25,790
method within the class still works the same.

31
00:02:27,110 --> 00:02:29,070
This class here has to test.

32
00:02:29,210 --> 00:02:31,520
One test is simply testing for one car.

33
00:02:31,550 --> 00:02:33,320
What happens if there's only one car?

34
00:02:33,590 --> 00:02:40,150
It adds it to the test and then it can check the average, but then it can also add two cars and then

35
00:02:40,170 --> 00:02:42,020
will check the average from the two cars.

36
00:02:42,770 --> 00:02:45,900
So this is the main idea when it comes to unit testing.

37
00:02:45,920 --> 00:02:51,550
You have a class which performs a specific task, in this case calculating the average.

38
00:02:51,830 --> 00:02:57,890
Then we want to include additional things here just to test that this class actually works how it should

39
00:02:57,890 --> 00:02:58,210
work.

40
00:02:59,440 --> 00:03:05,860
When it comes to executing tests that can be done in different ways, one ways is simple to use cradle

41
00:03:06,190 --> 00:03:08,860
verification and to run test.

42
00:03:09,990 --> 00:03:16,590
But this is like a graphical way on how we can start to test the command that we can run locally, but

43
00:03:16,590 --> 00:03:20,300
just as well in Lipsky is using the greatest rapper.

44
00:03:20,650 --> 00:03:24,450
So the great rapper where it's like this we call the great rapper.

45
00:03:25,630 --> 00:03:26,950
And we called test.

46
00:03:33,150 --> 00:03:37,350
Now, let's go ahead and make one of these tests fail, how will do this?

47
00:03:37,350 --> 00:03:39,710
It's a simply modify here a number.

48
00:03:39,720 --> 00:03:41,670
So actually the code will be OK.

49
00:03:41,760 --> 00:03:45,690
The test will not be OK itself because the test is wrong.

50
00:03:45,890 --> 00:03:48,750
It will show you how a failed test looks like.

51
00:03:56,890 --> 00:04:02,380
Now, you will be able to see that this command has failed and again, a report will be generated.

52
00:04:02,380 --> 00:04:09,000
So you can click on the report, however, here on the corner to open the browser and inside the browser,

53
00:04:09,010 --> 00:04:10,810
you'll be able to see a test summary.

54
00:04:10,810 --> 00:04:12,360
We'll see which are the failed test.

55
00:04:13,890 --> 00:04:19,230
You will see here that there is an insertion error that has occurred, expected was 15, but we got

56
00:04:19,230 --> 00:04:21,290
16 and this is why the tests fail.

57
00:04:21,779 --> 00:04:23,900
Of course, this is not a real fail.

58
00:04:24,180 --> 00:04:27,290
I have just made a test fail to demonstrate how it is.

59
00:04:27,300 --> 00:04:29,490
So I'm going to move it back to 15.

