I kind of answered why we want a test already but I would really want to make this clear again.
Testing so and with that I mean automated tests allows us to automatically test everything and there
is a star behind that because we only test what we define so only the tests we write.
But in theory it allows you to test everything in your application.
After every code adjustment after every code change therefore it's easy to detect breaking changes even
in places you might not have expected to rig upon your latest change.
And with automated tests we ensure that we have predictable clearly defined testing steps.
Our tests obviously always run in the exact same ways and we define all the steps in code and that of
course ensures that we can rely on the scenario always being the same.
If you are manually testing your app you might think you're doing the same thing as you did the last
time.
But in reality you might not be doing that because you forgot a step.
So that is why you should test.
How do you then set up your node project for testing no matter what you're building with node jars.
So no matter if you're building a page where you render the use on the server if you are building a
REST API or if you're building a graph El API you want to run tests automatically.
So you want to run code that tests your code and verdad you typically need a couple of tools.
You need a tool that executes your test code.
Sounds pretty simple but you need that and it should not only execute your code.
It should also give you a nice output that tells you whether your tests all pass or if a test failed.
So that is the first tool we need.
The second tool then is one that does not just run our code but that also allows us to define certain
conditions that have to be met.
So we want to assert certain results we want to find out if certain scenarios.
Well succeeded if test succeeded.
We wanted to find what success means in a certain test.
So we want to validate the test outcome.
Now for running the tests there are different tools for all these steps but for running these tests
one popular framework is mocha and we'll use mocha.
In this module here too and for asserting the results and defining conditions Chai is a popular choice
and we'll use that in this module too.
There are alternatives like just but mocha and Chai are really popular exist for a long time.
There are a lot of tutorials out there for you to dive deeper and therefore I will also use them here.
You're certainly not doing anything wrong when sticking to these tools.
Now as you will see for this module there will also be one ever tool we need when it comes to managing
side effects or working with external dependencies or certain complex scenarios.
There will use sign on which is a tool that allows us to create steps or marks and I will come back
to what that is later.
Now with that all out of the way I'd say let's install our basic testing tools and let's set up our
testing environment and then also write our first test so that we can gradually walk through our node
application and see how we could test it.