Another common stage that you may encounter when building S.I pipelines is the unit stage or the unit's
job?
First, what does the unit test?
Unit tests are responsible for testing only single units of code, typically only one class.
The execution time is very fast and they give instant feedback.
A common concept that you'll hear when discussing testing is the so-called testing pyramid.
It takes different forms and shapes, but always at the bottom of the test pyramid you will find the
unit test.
The reason why they are there is the reason I have specified before.
They run very, very fast.
They don't have a lot of preconditions.
They don't need the entire application and they are quite cheap.
They are easy to write, easy to execute.
So overall, the cost of having unit tests is very, very good.
Now, they are not the only kind of test that we can have in our application, just because the unit
tests to run doesn't mean that the entire application works.
But they are a very important level and they are present in practically any continuous integration pipeline.
Let me give you an example from the application.
Kareem Posman, if I go to the statistics folder, I'll be able to get to the average fleet age.
Now, this is something that is computed inside a code, which means that there is a Java class which
will go over all the vehicles that are in the database and you can view them here.
Will it take to build here and will do an average with this building?
Looking at a code, this can be found in source main Java Services Fleet Statistics Service.
And even if you're not too much into Java, you can easily see how this works, it goes over all the
cars and it all use the average function to get an average from the builder and will give this information
back.
Now, this code may or may not work, so we're not really sure if we need to add additional things to
the code, then it may break out of things that previously used to work.
So for that reason, we always write unit tests which test at this particular class or this particular
method within the class still works the same.
This class here has to test.
One test is simply testing for one car.
What happens if there's only one car?
It adds it to the test and then it can check the average, but then it can also add two cars and then
will check the average from the two cars.
So this is the main idea when it comes to unit testing.
You have a class which performs a specific task, in this case calculating the average.
Then we want to include additional things here just to test that this class actually works how it should
work.
When it comes to executing tests that can be done in different ways, one ways is simple to use cradle
verification and to run test.
But this is like a graphical way on how we can start to test the command that we can run locally, but
just as well in Lipsky is using the greatest rapper.
So the great rapper where it's like this we call the great rapper.
And we called test.
Now, let's go ahead and make one of these tests fail, how will do this?
It's a simply modify here a number.
So actually the code will be OK.
The test will not be OK itself because the test is wrong.
It will show you how a failed test looks like.
Now, you will be able to see that this command has failed and again, a report will be generated.
So you can click on the report, however, here on the corner to open the browser and inside the browser,
you'll be able to see a test summary.
We'll see which are the failed test.
You will see here that there is an insertion error that has occurred, expected was 15, but we got
16 and this is why the tests fail.
Of course, this is not a real fail.
I have just made a test fail to demonstrate how it is.
So I'm going to move it back to 15.