Unit testing frameworks and test runners
There are a lot of testing frameworks nowadays. In general, when we use a framework for testing, we need two things:
Test runner: This is the part of the framework that runs our tests and displays messages telling us whether they have passed or failed.
Assertions: These methods are used for the actual checks. For example, if you need to see whether an active variable is true, then you may write
expect(active).toBe(true)
instead of justif(active === true)
. It's just better for the reader of the test, and it also prevents some strange situations, for example, if you want to see whether a variable is defined. Theif
statement in the following code returnstrue
because the status variable has a value, and this value isnull
. In fact, we are asking "is the status variable initialized", and if we leave the test like that, we will get wrong results. That's why, we need an assertion library that has proper methods for testing, as shown in the following code...