Testing Types
Software testing is the process of evaluating a system to find defects and verify it meets requirements. Different testing levels and types serve different purposes in ensuring quality.
Testing Pyramid
TESTING PYRAMID
===============
/\
/ \ E2E Tests
/ \ (Few, slow, expensive)
/------\
/ \ Integration Tests
/ \ (Some, moderate speed)
/------------\
/ \ Unit Tests
/ \ (Many, fast, cheap)
/------------------\
Strategy: Write many unit tests, fewer integration
tests, and minimal E2E tests.
Unit Testing
UNIT TESTING
============
Tests individual functions/methods in isolation.
+-------------------+
| function add() | <-- Test this function
+-------------------+
Example:
test('adds two numbers', () => {
expect(add(2, 3)).toBe(5);
expect(add(-1, 1)).toBe(0);
expect(add(0, 0)).toBe(0);
});
Characteristics:
- Tests one unit at a time
- Fast execution
- No external dependencies (mocked)
- Easy to write and maintain
Integration Testing
INTEGRATION TESTING
===================
Tests how components work together.
+----------+ +----------+ +----------+
| API |---->| Database |---->| Cache |
+----------+ +----------+ +----------+
| |
v v
Tests real interactions between components.
Example:
test('creates user in database', async () => {
const user = await createUser({ name: 'Alice' });
const found = await findUser(user.id);
expect(found.name).toBe('Alice');
});
End-to-End (E2E) Testing
E2E TESTING
===========
Tests the entire application flow like a real user.
User -> Browser -> App -> Database -> Response
Example (Cypress):
describe('Login', () => {
it('logs in successfully', () => {
cy.visit('/login');
cy.get('#email').type('user@test.com');
cy.get('#password').type('password123');
cy.get('#login-btn').click();
cy.url().should('include', '/dashboard');
});
});
Characteristics:
- Tests complete user workflows
- Slow and expensive to run
- Tests real browser/app interactions
- Best for critical user paths
Other Testing Types
- Performance Testing: Load, stress, and scalability testing
- Security Testing: Vulnerability scanning and penetration testing
- Usability Testing: User experience and accessibility testing
- Regression Testing: Ensuring new changes don't break existing features
Key Takeaways
- The testing pyramid recommends many unit tests and few E2E tests
- Unit tests check individual components in isolation
- Integration tests verify component interactions
- E2E tests simulate real user workflows