Testing Types

Back

Loading concept...

πŸ§ͺ 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:

  1. You push code β†’ Pipeline starts
  2. Unit tests run β†’ Fast feedback
  3. Integration tests run β†’ Connections checked
  4. E2E tests run β†’ User journey verified
  5. 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! 🌍✨

Loading story...

Story - Premium Content

Please sign in to view this story and start learning.

Upgrade to Premium to unlock full access to all stories.

Stay Tuned!

Story is coming soon.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.