DEV Community

Victor Ng'ang'a
Victor Ng'ang'a

Posted on

Catching bugs before they bite: Django Testing

Week 5: Testing Everything—Unit, Integration, Functional & Beyond

TL;DR

I wrote and ran unit, integration, functional, smoke, and regression tests for Vimist’s services and endpoints—uncovered atomicity and signal bugs that only appeared on a live server.


1. Unit Tests for Core Services

  • What I tested:
    • process_sale
    • process_purchase
    • Credit account adjustments
  • Goal: Verify business logic in isolation before touching the database or HTTP layer.

2. Integration Tests Across Services

  • Focus: Ensure related functions play nicely together.
  • Scenarios:
    • Sale → inventory decrement
    • Purchase → inventory increment
    • Credit sale limits & repayments
    • Mixed payment methods: Cash, M-Pesa, Credit

3. Functional Flow Verification

  • End-to-end checks:
    • User signup + alert notification
    • Making purchases & payments
    • Low-stock and overdue payment alerts

4. Manual “Live” Testing Catches What Code Can’t

  • How: Hit the real API server with Postman/cURL.
  • Findings:
    • Sales weren’t fully atomic—errors raised but records still saved.
    • Duplicate credit entries when serializers and signals both processed transactions.

Lesson: Unit & integration tests are great—but manual/smoke tests on the live server are invaluable for catching signal- and transaction-related bugs.


Final Thoughts

Testing isn’t just a checkbox, it’s your fastest path to confidence and fewer late-night fire drills.

Next up: automating CI/CD pipelines to run these tests on every push.

See you in Week 6!

-vn-vision

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.