Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

Convention for writing unit tests


If you follow certain guidelines and principles while writing unit tests, it makes your code


maintainable and readable. The following are a few techniques that we can use while
writing unit tests for any application:


Unit testing should be carried out in small units—for a single class or a method.
Unit testing should be carried out in isolation, meaning that a unit test should not
be dependent on any other classes or methods, which is achieved by mocking
such dependencies.
Since unit testing is done in smaller parts, these should be very lightweight,
which makes the tests run faster.
A unit test should test the behavior of a unit of an application. It should expect a
certain value and return a certain output.
Since unit tests are done in isolation, the ordering of tests for different units does
not create a problem.
Follow Do not Repeat Yourself (DRY); the code should not be repeatable.
Add comments explaining where you can, which explains the why part of the
test so that it is understandable.

An introduction to end-to-end test


End-to-end testing is the testing of our application from start to finish. Where as unit testing


tests whether the functionalities of your application work independently or not—end-to-


end testing checks whether the flow of the application is performing as expected or


not. Usually, the end-to-end testing makes sure that all the user interactions are carried out
the way as expected. End-to-end testing ensures that the flow of the application is working


as expected.

Free download pdf