Introduction to Testing
Introduction to Software Testing
Software testing is a crucial step in the development process that helps identify errors, bugs, and other issues that may affect the quality of the software. It will also help prevent bugs that end up in production code from happening again.
Methodologies/Types of Tests
There are different types of testing methodologies: Unit Testing, Integration Testing, End-To-End Testing; Acceptance Testing, etc. For this introduction, we will focus on the first two.
Unit Testing
Unit tests check the functionality of individual components of an application. A "unit" can be a function, method, or class and is tested in isolation from the rest of the system.
Integration Testing
The main goal of integration testing is to identify errors that may arise from the interaction between different components of an application. It involves testing the communication and data exchange between different units and verifying that they work as expected.
Some also consider testing a unit that interacts with the "outside world" (any code that uses AJAX, localStorage, etc.) an integration test.
Mocking Dependencies
When testing code that uses any kind of dependency such as AJAX, localStorage, or third-party libraries, we can usually safely assume that the dependency is itself well-tested and works correctly.
To isolate the testing to only our code we use a technique called mocking where we simulate the behaviour of the dependencies. i.e. Replacing axios
with a fake ("mock") axios
that just returns data without making an actual AJAX request.
Automated Testing Tools
There are various JavaScript testing frameworks like MochaJS, Jasmine, and Jest that help automate the process. For this class we will use Jest.
Last updated
Was this helpful?