0
0
Testing Fundamentalstesting~15 mins

Why systematic techniques improve coverage in Testing Fundamentals - Automation Benefits in Action

Choose your learning style9 modes available
Verify that systematic testing techniques improve test coverage
Preconditions (3)
Step 1: Open the calculator application
Step 2: Enter 5 in the first number input field
Step 3: Enter 3 in the second number input field
Step 4: Click the 'Add' button
Step 5: Verify the result is 8
Step 6: Click the 'Subtract' button
Step 7: Verify the result is 2
Step 8: Click the 'Multiply' button
Step 9: Verify the result is 15
Step 10: Click the 'Divide' button
Step 11: Verify the result is 1.6667 (rounded to 4 decimals)
Step 12: Repeat the above steps with inputs 0 and 0
Step 13: Repeat the above steps with inputs -1 and 1
✅ Expected Result: All operations return correct results for all input sets, demonstrating that systematic testing covers normal, boundary, and edge cases.
Automation Requirements - Selenium with Python
Assertions Needed:
Verify displayed result matches expected calculation for each operation
Verify results for multiple input sets to cover different cases
Best Practices:
Use explicit waits to handle UI loading
Use parameterized tests or loops for multiple input sets
Use clear and maintainable locators (id or name attributes)
Separate test data from test logic
Automated Solution
Testing Fundamentals
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import unittest

class CalculatorSystematicTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('http://localhost:8000/calculator')  # Replace with actual URL
        self.wait = WebDriverWait(self.driver, 10)

    def tearDown(self):
        self.driver.quit()

    def calculate_and_verify(self, num1, num2, operation, expected):
        driver = self.driver
        wait = self.wait

        input1 = wait.until(EC.presence_of_element_located((By.ID, 'num1')))
        input2 = driver.find_element(By.ID, 'num2')
        result_field = driver.find_element(By.ID, 'result')

        input1.clear()
        input1.send_keys(str(num1))
        input2.clear()
        input2.send_keys(str(num2))

        button = driver.find_element(By.ID, operation)
        button.click()

        wait.until(lambda d: result_field.text != '')
        actual_result = result_field.text.strip()

        self.assertAlmostEqual(float(actual_result), expected, places=4, msg=f'Failed for {operation} with inputs {num1}, {num2}')

    def test_systematic_coverage(self):
        test_data = [
            (5, 3),
            (0, 0),
            (-1, 1)
        ]

        for num1, num2 in test_data:
            self.calculate_and_verify(num1, num2, 'add', num1 + num2)
            self.calculate_and_verify(num1, num2, 'subtract', num1 - num2)
            self.calculate_and_verify(num1, num2, 'multiply', num1 * num2)
            if num2 != 0:
                self.calculate_and_verify(num1, num2, 'divide', num1 / num2)
            else:
                # For division by zero, expect some error or empty result
                driver = self.driver
                driver.find_element(By.ID, 'divide').click()
                result_field = driver.find_element(By.ID, 'result')
                self.wait.until(lambda d: result_field.text != '')
                self.assertIn('error', result_field.text.lower() + ' ', 'Expected error message for division by zero')

if __name__ == '__main__':
    unittest.main()

This test script uses Selenium with Python's unittest framework to automate the calculator app.

setUp opens the browser and navigates to the calculator page.

calculate_and_verify is a helper method that inputs numbers, clicks the operation button, waits for the result, and asserts the output matches expected value with 4 decimal precision.

The test_systematic_coverage method runs the helper for three input sets: normal numbers, zeros, and negative/positive mix. This covers typical, boundary, and edge cases systematically.

Explicit waits ensure elements are ready before interaction. Clear locators by ID keep selectors stable. Assertions check correctness precisely.

This approach shows how systematic testing improves coverage by verifying multiple scenarios, not just one.

Common Mistakes - 3 Pitfalls
Using hardcoded sleep instead of explicit waits
Using brittle XPath locators that break easily
Testing only one input set
Bonus Challenge

Now add data-driven testing with 3 different input sets using unittest subTest or pytest parameterize.

Show Hint