Hello, everyone. So in this section of
course, we will be looking into the basic introduction to unit testing. We will be
looking into some terminologies related to unit testing. So the first thing which comes
into our mind is what is unit testing? So if you see a unit test is a piece of code
written by a developer to test certain functionality of code. Now, what do we mean
by it? So, usually in day to day work, a developer write a functionality of code in
its development phase. But in order to test that whether the code written by him is
correct, developer writes yet another piece of code, which we call unit test. And that
piece of code basically provides a feedback to developer that whatever the functionality
of code he has written is correct. Also, friends, you can see, the functionality of
code, which is written by a developer is basically written inside a class. And let's
say you want to test that class. So, there is a term associated with that class, which you
want to test. We call it a system or class under test. And the method which is written
inside this class, where the functionality of code lies in which the developer want to test
is actually called as method under test. So, friends, what do unit tests does this unit
tests instantiate the class under test, because you want to test that particular
class, then it executes the method under test, because what are the functionality of
code which you want to test is written inside this method. And finally, it verifies that it
worked as expected. Moving ahead. So, friends what makes a good unit test. So, you can see
a good unit test should be easy to write. So, why it should be easy to write because, so as
that term is unit test. So, by unit, we mean the small piece of code. And if you want to
test a small piece of code, then the whatever test cases around it, it should be easy to
write. And also, the code which developer want to test can have many scenarios. So, in
order to test those scenarios, the developer has to write many unit tests. So, therefore,
the unit test should be easy to write, meaning that developers shouldn't put a lot
of efforts in writing those unit tests. The second thing which makes a good unit test
should be its readability. So as we discussed that a good unit test is easy to write, it
should be easy to read. So here by readability, we mean that the test should
show its intent that what it is actually testing, let's have a particular developer
has written some unit test. So for the other developer, the test case should be readable.
So that the other developer doesn't have to put a lot of effort in figuring out what
actually the unit test does. The third thing, which makes a good unit test is that it
should be reliable. Server reliability, we mean that, let's say we have written few unit
tests. So those unit tests shouldn't be dependent on each other, or the environment
in which they are getting executed. So for example, let's say we are running few unit
tests on one particular machine. And those are getting succeeded. And the same unit test
case if you are running on other machine, or getting failed. So those unit tests are not
good unit tests, because they are not reliable. Sometime it may happen that the
unit tests are running on one machine. And let's say if you are running it on any
continuous integration server, they are getting failed. So those unit tests are not
reliable. The fourth characteristic, which makes a good unit test is it should be fast.
So by fast, we mean that when we execute a unit test, it should provide the feedback to
the developer very quick. Because in a particular project, our developer writes
hundreds or 1000s of unit tests. And what usually the developer does, is that they run
the unit test every time so that they can get a feedback about a system which they are
testing. So if they are running those tests very frequently, they should not wait. The
feedback should be provided to them very quick. So therefore, a good unit test is a
test which executes fast and provides the feedback to developer very quick. The last
characteristic of a good unit test is it should be isolated. So let's say if you want to test a particular
class, and that Last is dependent on external services such as database or network calls or
any other external services which takes in time. So what happens is doula the external
factors and they may take time to bring back the results. So they are consuming much time,
then what happens is the unit tests are no longer fast. So, therefore, whenever you want
to unit test a particular class, that class should be isolated from the external factors
so that we can test that last by you our unit test. And those unit tests are running fast.
They are reliable, readable and easy to write. So, for him, these are the few
characteristics of the good unit test. So, friends I hope you liked this video. Thanks
Have a nice day.