Importance of Testing
E2E testing have a limitation, that it’s not helpful to find the root cause of failure, which is a demerit in case of large projects.
Unit Testing: Unit testing involves testing small pieces of codes independently. It helps to reduce bug occurrence during deployment. This is a critical issue while developing a software. In short, we can say unit testing is a process that breaks the software into specific functions and then performs testing individually. Unit testing aims at identifying bugs before it’s pushed to production. Unit tests are aimed to test for logic, errors, functions and code that needs to be maintained throughout the project’s life-cycle.
Integration Testing: Integration testing is the one where individual units are integrated and tested combining them as a group. Integration test typically focus on small number of modules and test their interactions.
It aims to cover multiple units which involves testing two or more small components of the application and ensure that they integrate and work as expected. It helps in finding major bugs when multiple components run together in the application.
A project which is primarily focused on computation or data, should have more unit tests and fewer integration tests.
Mocha & Chai
Jasmine is a Behavior Driven Development(BDD) framework for testing JS code which doesn’t depend on JS framework. Jasmine ships with an HTML test runner that executes the tests in the browser. Also, it doesn’t require DOM and it the clean, obvious syntax helps in easy writing of tests.
Karma is an ideal test runner for writing and running unit tests while developing the application. It is an important and essential tool for testing that spawns web server and executes source code against the test code for each of the connected browsers. The results of each tests against each browser is examined and displayed to the developer via command line. This helps developer to identify which of the browsers and tests passed or failed. Moreover, we can call it as an integral part of the project under development that involves continuous integration process.
Usually Jasmine and Karma are used together to perform Unit testing or Integration testing.
Protractor is an end-to-end testing framework for AngularJS applications. It which helps to explore the application like user experience and runs tests against the application running in a real browser.
Angular testing utilities
It creates a test environment for the Angular application code under test. One can use them to apply condition and control parts of the application as they interact within the Angular environment.
More details available here.
Intern provides features that makes writing and running tests easily for small improvements like glob support for listing suites, ability to efficiently manage local Selenium server. The highlight of this testing framework is that it maintains the goal of making easier to write quality tests and provides out-of-box support for both unit testing as well as functional testing.
CasperJS is a suite of libraries on top of PhantomJS which extends its capabilities as a client for automated web page testing that makes end to end testing easy. Since PhantomJS doesn’t have testing utilities, CasperJS is used as it provides testing utilities such as assertions, organizing tests, keeping track of the successful and failed tests. Although it’s time consuming its end-to-end test results are vital for testing critical paths.
CodeceptJS is a tool that makes acceptance testing quick and easy. It provides an engine that allows to write test once and run it using libraries of user’s choice, i.e., Protractor, Nightmare, WebDriverio etc
Testing pattern for complex workflows
It’s better to test an application starting from the initial stage, than at the time of bugs and issues post release. But at times there are few projects which already exist and have a lot of legacy code, in that case it’s better to start testing gradually. It’s not easy to get 100% coverage in existing codebase. Implementing tests gradually is better than creating a big pull request with all tests at a time.
If one aims to have a reliable and maintainable codebase then regular code testing is mandatory. The code quality should be maintained so that the codebase can be easily used, modified and extended by any developer who joins in future and is new to the project. This is possible only if tests are conducted in regular intervals. Testing helps to detect failures before the code is merged to stable branch or production.