π§ͺ Testing in CI/CD: The 8 Test Types That Guard Your Code
π The Story: Meet the Quality Control Team
Imagine youβre building a giant LEGO castle. Before you show it to everyone, you need helpers to check if itβs really good. Each helper has a special job to make sure your castle is perfect!
In software, we call these helpers βtestsβ β and in CI/CD (Continuous Integration/Continuous Deployment), they run automatically every time you make changes. Letβs meet our 8 amazing test helpers!
π§± 1. Unit Testing β The Brick Inspector
What Is It?
Unit testing checks one tiny piece of code at a time. Like checking if a single LEGO brick is the right shape.
Simple Example
// The function
function add(a, b) {
return a + b;
}
// The unit test
test('add 2 + 3 equals 5', () => {
expect(add(2, 3)).toBe(5);
});
Real Life
- You test if a button changes color when clicked
- You test if a calculator adds numbers correctly
- Each test checks just ONE thing
Why It Matters
π― Fast to run, easy to fix. If a brick is broken, you find it immediately!
π 2. Integration Testing β The Connection Checker
What Is It?
Integration testing checks if different pieces work together. Like checking if your LEGO walls connect properly to the LEGO base.
Simple Example
// Testing if database + server work together
test('save user to database', async () => {
const user = { name: 'Sam' };
await database.save(user);
const found = await database.find('Sam');
expect(found.name).toBe('Sam');
});
Real Life
- Does the login page talk to the database correctly?
- Does the payment system connect to the bank?
- Do the puzzle pieces fit together?
graph TD A["π€ User Input"] --> B["π₯οΈ Server"] B --> C["πΎ Database"] C --> D["β Data Saved!"]
βοΈ 3. Functional Testing β The Feature Tester
What Is It?
Functional testing checks if a complete feature works as expected. Like testing if your LEGO drawbridge opens and closes properly.
Simple Example
test('user can sign up', () => {
// Type email
fill('email', 'kid@example.com');
// Type password
fill('password', 'secret123');
// Click button
click('Sign Up');
// Check result
expect(screen).toShow('Welcome!');
});
Real Life
- Can a user add items to a shopping cart?
- Can a user send a message?
- Does the βLikeβ button actually work?
π Focus: Does the feature do what itβs supposed to do?
π€οΈ 4. End-to-End Testing (E2E) β The Full Journey Tester
What Is It?
E2E testing follows a complete user journey from start to finish. Like building and testing the entire LEGO castle adventure β from entering the gate to reaching the throne room!
Simple Example
test('complete shopping journey', async () => {
await visit('/');
await click('Products');
await click('Add to Cart');
await click('Checkout');
await fill('card', '4111111111111111');
await click('Pay');
expect(screen).toShow('Order Complete!');
});
Real Life
- User opens app β logs in β buys item β receives confirmation
- Visitor reads article β signs up β gets welcome email
graph TD A["π Home Page"] --> B["π Browse"] B --> C["π Add to Cart"] C --> D["π³ Checkout"] D --> E["β Success!"]
π¨ 5. Smoke Testing β The Quick Health Check
What Is It?
Smoke testing is a super quick test to check if the basic things work. Like quickly checking if your LEGO castle doesnβt fall apart when you touch it.
Simple Example
test('app starts without crashing', () => {
const app = startApp();
expect(app.isRunning()).toBe(true);
});
test('home page loads', async () => {
const page = await fetch('/');
expect(page.status).toBe(200);
});
Why βSmokeβ?
π Old engineers would turn on electronics and check: βIs there smoke?β No smoke = probably okay!
Real Life
- Does the website open?
- Does the app launch?
- Does the login page appear?
π 6. Regression Testing β The βNothing Brokeβ Checker
What Is It?
Regression testing makes sure that new changes didnβt break old things. Like checking if adding a tower to your castle didnβt knock down the walls you built yesterday.
Simple Example
// After adding new feature...
test('old login still works', () => {
login('user', 'pass123');
expect(screen).toShow('Dashboard');
});
test('old search still works', () => {
search('puppies');
expect(results.length).toBeGreaterThan(0);
});
Real Life
- Added dark mode? Make sure light mode still works!
- Added new payment option? Make sure credit cards still work!
graph TD A["π New Code Added"] --> B{π Run All Old Tests} B -->|Pass| C["β Safe to Deploy!"] B -->|Fail| D["β οΈ Something Broke!"]
β‘ 7. Performance Testing β The Speed Tester
What Is It?
Performance testing checks how fast your app runs. Like timing how quickly you can build your LEGO castle.
Simple Example
test('page loads in under 2 seconds', async () => {
const start = Date.now();
await loadPage('/home');
const end = Date.now();
const time = end - start;
expect(time).toBeLessThan(2000);
});
What We Measure
| Metric | What It Means |
|---|---|
| Load Time | How fast pages open |
| Response Time | How fast buttons respond |
| Memory Use | How much space it needs |
Real Life
- Is the app fast enough for users?
- Does it slow down with more data?
ποΈ 8. Load Testing β The Crowd Tester
What Is It?
Load testing checks if your app works when LOTS of people use it at once. Like inviting 100 friends to play with your LEGO castle at the same time β does it survive?
Simple Example
test('handle 1000 users', async () => {
const users = simulateUsers(1000);
await Promise.all(
users.map(u => u.visitPage('/'))
);
expect(server.isHealthy()).toBe(true);
});
Real Life
- Can the shop handle Black Friday traffic?
- What happens when a post goes viral?
- Will the app crash during a big event?
graph TD A["π€ 1 User"] --> S["π₯οΈ Server"] B["π€ 10 Users"] --> S C["π€ 100 Users"] --> S D["π€ 1000 Users"] --> S S --> E{Still Working?} E -->|Yes| F["β Passed!"] E -->|No| G["π₯ Crashed!"]
πΊοΈ The Complete Testing Pyramid
graph TD subgraph "πΊ Test Pyramid" A["E2E Tests<br/>Few & Slow"] --> B["Integration Tests<br/>Some & Medium"] B --> C["Unit Tests<br/>Many & Fast"] end
| Test Type | Speed | Quantity | When to Run |
|---|---|---|---|
| Unit | β‘ Very Fast | Many | Every save |
| Integration | π Fast | Some | Every commit |
| E2E | π’ Slower | Few | Before deploy |
π― Quick Summary: All 8 Tests
| # | Test Type | What It Checks | Analogy |
|---|---|---|---|
| 1 | Unit | One tiny piece | Single LEGO brick |
| 2 | Integration | Pieces together | Bricks connecting |
| 3 | Functional | Features work | Drawbridge opens |
| 4 | E2E | Full journey | Entire castle tour |
| 5 | Smoke | Basic health | No falling apart |
| 6 | Regression | Nothing broke | Old walls still stand |
| 7 | Performance | Speed | How fast to build |
| 8 | Load | Handles crowds | 100 friends playing |
π Why This Matters in CI/CD
In CI/CD, all these tests run automatically when you push code:
- You push code β Pipeline starts
- Unit tests run β Fast feedback
- Integration tests run β Connections checked
- E2E tests run β User journey verified
- All pass? β Code gets deployed! π
π Youβre not alone! These 8 test types work as a team to catch bugs before users ever see them.
π‘ Remember This!
Testing is like having superhero friends who check your work:
- π¦Έ Unit = The Detail Detective
- π¦Έ Integration = The Connection Captain
- π¦Έ Functional = The Feature Fighter
- π¦Έ E2E = The Journey Guardian
- π¦Έ Smoke = The Quick Scout
- π¦Έ Regression = The Memory Master
- π¦Έ Performance = The Speed Racer
- π¦Έ Load = The Crowd Controller
Together, they make sure your code is safe, fast, and ready for the world! πβ¨
