Node.js
/Beginner
Unit Testing
Definition
A software testing method where individual units or components of a software are tested in total isolation from the rest of the application.
Explain Like I'm New
Testing a single puzzle piece. If you have a function that calculates taxes, a Unit Test only runs that specific function. It intentionally disconnects from the database and the network to prove that the raw math logic works perfectly on its own.
Real World Example
Writing a test for `calculateDiscount(price, code)`. You feed it 100 and 'SAVE20', and expect it to return 80. You don't test if the web server can receive the request, just the math.
Common Use Cases
- •Validating core business logic
- •Ensuring pure functions behave correctly
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- Should a Unit Test interact with a real Database?
intermediate
- What is a 'Pure Function' in relation to unit testing?