Skip to content

Learning Software Testing: Unit, Integration, E2E, and API Testing

Published: at 12:00 AM (2 min read)

Learning Software Testing: Unit, Integration, E2E, and API Testing

This blog explores key concepts in software testing, from isolated unit tests to comprehensive API validations. We’ll cover the characteristics, best practices, and examples for each type.

Unit Testing

A unit testing verifies one small piece of logic (a function/class) in isolation. Here, unit means smallest testable behaviour, not the whole system.

Features of Good Unit Testing

Features of Bad Unit Testing

from math_utils import calculate_discount
import pytest
def test_calculate_correct_discount():
    assert calculate_discount(100, 10) == 90
def calculate_discount(price, percent) -> float:
    if percent < 0 or percent > 100:
        raise ValueError("Invalid percent")
    return price - (price * percent) /100

How to test with mock

import pytest
from utils.user_service import get_username
@pytest.mark.asyncio
async def test_get_username():
    async def fake_fetch(uid):
        return {"name": "Bibe"}

    name = await get_username(fake_fetch, "1")
    assert name == "Bibek"
async def get_username(fetch_user, user_id: str):
    user = await fetch_user(user_id)
    return user["name"]

Integration Testing

Characteristics

End-to-End (E2E) Tests

Characteristics

API Testing

Test categories for apis:

Functional

In this we test:

Performance

In this, we test:

Security

In this, we test:

Reliability

In this, we test:

Key API Testing Strategies

Positive Testing

Valid inputs with expected 2xx responses

Negative Testing

Invalid inputs, mal-informed data (4xx / 5xx)

Boundary Testing

Minimum/maximum values, pagination limits

Contract Testing

Ensuring API meets Open API specification

State Transition Testing

Multi-step workflows (e.g, create -> update -> delete)


Previous Post
Learn TypeScript
Next Post
Hoisting and Temporal Dead Zone in JavaScript