Why systematic techniques improve coverage in Testing Fundamentals - Automation Benefits in Action
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.
Now add data-driven testing with 3 different input sets using unittest subTest or pytest parameterize.
Practice
Solution
Step 1: Understand the purpose of systematic techniques
Systematic techniques plan tests to cover different important scenarios, such as boundaries and input groups.Step 2: Compare options with this purpose
Only They organize tests to cover important cases like boundaries and input groups. describes organizing tests to cover important cases, which matches the purpose.Final Answer:
They organize tests to cover important cases like boundaries and input groups. -> Option DQuick Check:
Systematic testing = organized coverage [OK]
- Thinking fewer tests always mean better coverage
- Confusing random testing with systematic testing
- Believing UI testing covers all bugs
Solution
Step 1: Identify systematic techniques
Boundary value analysis is a known systematic technique focusing on edge cases.Step 2: Evaluate options
Testing only the first and last inputs of a range (boundary value analysis). matches a systematic technique; others describe random or incomplete testing.Final Answer:
Testing only the first and last inputs of a range (boundary value analysis). -> Option CQuick Check:
Boundary value analysis = systematic test [OK]
- Confusing random testing with systematic
- Ignoring edge cases in tests
- Assuming popular features cover all bugs
inputs = [1, 5, 10, 15, 20]
covered_groups = set()
for i in inputs:
if i <= 5:
covered_groups.add('low')
elif i <= 15:
covered_groups.add('medium')
else:
covered_groups.add('high')
print(sorted(covered_groups))What will be the output?
Solution
Step 1: Analyze input classification
Inputs 1 and 5 are 'low', 10 and 15 are 'medium', 20 is 'high'.Step 2: Determine covered groups
All three groups 'low', 'medium', and 'high' are added to covered_groups.Final Answer:
['low', 'medium', 'high'] -> Option AQuick Check:
All input groups covered = ['low', 'medium', 'high'] [OK]
- Missing the 'high' group for input 20
- Assuming 15 is 'high' instead of 'medium'
- Forgetting to sort the output
def test_boundary(x):
if x > 0 and x < 10:
return 'Inside'
else:
return 'Outside'
print(test_boundary(0))
print(test_boundary(10))What is the problem with this test regarding boundary coverage?
Solution
Step 1: Understand boundary conditions in code
The code checks if x is strictly greater than 0 and less than 10, so 0 and 10 are excluded.Step 2: Identify test coverage issue
Testing 0 and 10 returns 'Outside', missing the boundary values as 'Inside' cases.Final Answer:
It misses testing the exact boundary values 0 and 10 correctly. -> Option AQuick Check:
Boundary values excluded = coverage gap [OK]
- Assuming 0 and 10 are inside the range
- Ignoring strict inequality signs
- Thinking syntax error causes the problem
Solution
Step 1: Identify coverage goals
We want to cover edge cases and different input groups systematically.Step 2: Match techniques to goals
Boundary value analysis covers edges (1 and 100), equivalence partitioning divides inputs into groups.Step 3: Evaluate options
Use boundary value analysis for edges and equivalence partitioning for input groups. combines both techniques, improving coverage best; others are incomplete or random.Final Answer:
Use boundary value analysis for edges and equivalence partitioning for input groups. -> Option BQuick Check:
Combine boundaries + partitions = best coverage [OK]
- Relying on random or single-value tests
- Ignoring input group diversity
- Testing only multiples or arbitrary subsets
Ready to prove it?
Pass the test and this pattern moves unknown
