What is software testing and why is it needed?
60-second answer
Software testing is the process of checking that a product works as expected and finding defects before users do. We compare the actual behaviour of the software with the expected behaviour from the requirements. It's needed because bugs found late are expensive, bugs in production hurt users and the business, and testing gives the team confidence to release. Testing can't prove there are no bugs, but it reduces the risk of failure to an acceptable level.
Explanation
Testing has two goals: find defects and build confidence that the product meets requirements and user needs.
It is needed because:
- Humans make mistakes in requirements, design and code.
- The cost of fixing a defect grows the later it's found. A requirement bug fixed in review costs minutes; the same bug in production can cost a hotfix, a rollback and lost customers.
- Some domains (banking, healthcare, aviation) have legal and safety requirements.
- Testing gives data for a release decision: what was tested, what failed, what risk remains.
A good one-line definition for interviews: testing is a risk-reduction activity that provides information about quality to stakeholders.
Example
In 2012 a trading firm, Knight Capital, deployed untested code to production and lost about $440 million in 45 minutes. A smaller everyday example: an e-commerce site shows the wrong total when a coupon and a sale price both apply. Testing the checkout with combined discounts before release would have caught it.
Sample code
// The idea of testing in code: compare actual vs expected.
int expected = 90;
int actual = cart.totalAfterDiscount(100, 10); // 10% off
if (actual != expected) {
throw new AssertionError("Expected " + expected + " but got " + actual);
}