Menu
Theme
Bachelor of Science in Computer Science
Course Content

Testing

Software Engineering

Habari, Future Tech Mtaalam! Let's Talk About Testing.

Imagine you're the best chapati chef in your neighbourhood. You've mixed the flour, kneaded the dough, and cooked a perfect, flaky chapati. But before you sell it to a hungry customer, what's the one thing you MUST do? You taste it, right? To make sure it’s not too salty, not too hard, just perfect. Software testing is exactly that – it's the 'tasting' of your software to make sure it's delicious and ready for the world!

In software engineering, we don't just write code and hope for the best ("kuomba Mungu"). We are engineers! We test our work rigorously to build strong, reliable, and secure systems that Kenyans can depend on every day.

So, What Exactly is Software Testing?

Simply put, Software Testing is the process of evaluating and verifying that a software product or application does what it is supposed to do. The goal is to find errors, gaps, or missing requirements contrary to the actual requirements. It’s our quality assurance, our 'seal of approval' before an app like M-Pesa or a system like the KPLC token service goes live.

Image Suggestion:

A vibrant, modern tech hub office in Nairobi. A diverse group of young Kenyan developers, both male and female, are gathered around a large monitor. One of them is pointing at a line of code, while others are discussing it animatedly. The whiteboard behind them is filled with flowcharts and the word 'BUG?' circled in red. The atmosphere is collaborative and focused. Style: Bright, realistic digital art.

Why Bother Testing? Si Itawork Tu?

Ah, the classic question! Why spend time testing when you can be writing the next big feature? Well, think about the last time your banking app crashed right when you needed to pay a bill. Frustrating, wasn't it? Proper testing is the shield that protects both the user and the company. Here’s why it's a big deal:

  • Saves Money: Finding and fixing a bug early in development is cheap. Finding it after the app has launched and thousands of users are complaining? That’s an expensive disaster! It’s like a fundi fixing a small crack in a wall versus rebuilding the whole wall after it collapses.
  • Customer Satisfaction: A reliable app builds trust. If your boda-boda hailing app always shows the correct fare and never crashes, people will keep using it.
  • Security: We live in a world of digital transactions. Testing helps find vulnerabilities that hackers could exploit to steal data or money. Imagine the chaos if the M-Pesa system had a security flaw!
  • Reputation: A company's reputation can be shattered by a single, major software failure. Good testing protects the brand.

The Different Levels of 'Kupima' (Testing) Your Code

Testing isn't just one single action. It's a series of checks at different levels, like building a house. You check the foundation, then the walls, then the roof, and finally, the whole house. In software, we call this the V-Model or the testing pyramid.


   A Simple Testing Flow:

   [Step 1: Write a small piece of code (a 'unit')]
                     |
                     V
   [Step 2: UNIT TESTING]
   (Test that single piece in isolation)
                     |
                     V
   [Step 3: Combine it with other pieces]
                     |
                     V
   [Step 4: INTEGRATION TESTING]
   (Test if the pieces work together correctly)
                     |
                     V
   [Step 5: Assemble the whole application]
                     |
                     V
   [Step 6: SYSTEM TESTING]
   (Test the entire app from start to finish)
                     |
                     V
   [Step 7: Give it to real users for feedback]
                     |
                     V
   [Step 8: USER ACCEPTANCE TESTING (UAT)]
   (Does the customer agree this is what they wanted?)
  • Unit Testing: Testing the smallest piece of code possible, a single function. For example, testing ONLY the function that calculates the transaction fee on M-Pesa for sending KES 500.
  • Integration Testing: Testing how different parts work together. For example, does the M-Pesa fee calculation function correctly pass the fee to the "Confirm Transaction" screen?
  • System Testing: Testing the entire, complete system. For example, going through the whole M-Pesa process: Login -> Enter Number -> Enter Amount -> See Fee -> Confirm with PIN -> Get SMS.
  • User Acceptance Testing (UAT): The final step. Real users (or the client) test the software to see if it meets their needs. It's like letting a few trusted customers taste your chapati before you open your food stall for the day.

Let's Get Technical: A Peek at a Unit Test

Let's imagine we are building a simple function for a ride-hailing app that calculates a boda-boda fare. The rule is: KES 100 base fare + KES 20 per kilometer.


# The function we want to test (e.g., in a file named fare_calculator.py)

def calculate_boda_fare(distance_km):
    """Calculates the fare for a boda-boda ride."""
    if distance_km < 0:
        raise ValueError("Distance cannot be negative")
    base_fare = 100
    rate_per_km = 20
    total_fare = base_fare + (distance_km * rate_per_km)
    return total_fare

# A simple unit test for our function (e.g., in a file named test_fare_calculator.py)
# This uses Python's built-in 'unittest' framework.

import unittest
from fare_calculator import calculate_boda_fare

class TestFareCalculator(unittest.TestCase):

    def test_normal_distance(self):
        # Test a typical 5km trip
        self.assertEqual(calculate_boda_fare(5), 200) # Expected: 100 + (5 * 20) = 200

    def test_zero_distance(self):
        # Test a trip with no distance
        self.assertEqual(calculate_boda_fare(0), 100) # Expected: 100 + (0 * 20) = 100
        
    def test_negative_distance(self):
        # Test that our function correctly handles bad input
        with self.assertRaises(ValueError):
            calculate_boda_fare(-10)

Real-World Scenario:

Why is that `test_negative_distance` so important? Imagine a bug in the app's GPS that sometimes reports a negative distance. Without that test and the error handling, your function might calculate a fare of less than KES 100, causing the boda rider to lose money! Small unit tests prevent big, real-world problems.

Black Box vs. White Box: Peeking Inside the 'Kibanda'

Testers use two main strategies. Think of it like testing a radio.

  • Black Box Testing: You don't know what's inside the radio. You just test the functions: Does the power button work? Can you change the station? Does the volume knob work? You test the inputs and check the outputs without seeing the internal code. This is testing from a user's perspective.
  • White Box Testing (or Glass Box): You open the radio and look at the circuits. You test the internal pathways and connections to ensure everything is wired correctly. In software, this means the tester looks at the actual code to design their test cases. Our unit test example above is a form of white-box testing because we wrote the test based on our knowledge of the code's logic.
Image Suggestion:

A simple, split-screen cartoon. On the left, titled 'Black Box', a person is shown interacting with a plain black box that has buttons and a screen; they are just checking if the buttons do what they're supposed to. On the right, titled 'White Box', the box is transparent (like glass), and the person is looking inside at the gears and wires, tracing the connections to see how it works. Style: Simple, clear, educational infographic.

Let's Do Some Math: How 'Good' is Our Code?

We can use simple metrics to get an idea of our code quality. One common metric is Defect Density.

It measures the number of confirmed defects (bugs) found in the software divided by the size of the software (often measured in thousands of lines of code, or KLOC).


Formula:
Defect Density = (Total Number of Defects) / (Size of the Software in KLOC)

Example Calculation:
- Your team is building a new feature for a Sacco's mobile app.
- The total code written for the feature is 4,000 lines. (This is 4 KLOC)
- During testing, your team finds and confirms 12 defects.

Calculation:
Defect Density = 12 / 4
Defect Density = 3 defects per KLOC

This number helps you compare the quality of different projects or track your team's improvement over time. A lower number is generally better!

Your Mission, Should You Choose to Accept It

Congratulations! You've just taken a deep dive into the world of software testing. It's not just about finding what's broken; it's about building confidence, ensuring quality, and creating products that people can trust and enjoy.

As you continue your journey in software engineering, remember the chapati chef. Always taste your work. Be proud not just of the code you write, but of how well it works. A good developer writes code, but a great developer writes testable, reliable, and high-quality code. Kazi nzuri!

Pro Tip

Take your own short notes while going through the topics.

KenyaEdu
Add KenyaEdu to Home Screen
For offline access and faster experience