Equivalence partitioning in Testing Fundamentals - Build an Automation Script
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 TestAgeInputEquivalencePartitioning(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://example.com/age-form') # Replace with actual URL self.wait = WebDriverWait(self.driver, 10) def tearDown(self): self.driver.quit() def submit_age_and_get_message(self, age): age_input = self.wait.until(EC.visibility_of_element_located((By.ID, 'age'))) age_input.clear() age_input.send_keys(str(age)) submit_button = self.driver.find_element(By.ID, 'submit') submit_button.click() message = self.wait.until(EC.visibility_of_element_located((By.ID, 'message'))) return message.text def test_age_less_than_18(self): message = self.submit_age_and_get_message(17) self.assertEqual(message, 'Age must be between 18 and 60') def test_age_between_18_and_60(self): for valid_age in [18, 30, 60]: message = self.submit_age_and_get_message(valid_age) self.assertEqual(message, 'Form submitted successfully') def test_age_greater_than_60(self): message = self.submit_age_and_get_message(61) self.assertEqual(message, 'Age must be between 18 and 60') if __name__ == '__main__': unittest.main()
This test script uses Selenium with Python's unittest framework to automate the equivalence partitioning test for an age input field.
setUp opens the browser and navigates to the form page.
tearDown closes the browser after each test.
The helper method submit_age_and_get_message enters the age, submits the form, and waits for the message to appear, returning its text.
Three test methods cover the partitions:
test_age_less_than_18tests an invalid low age and expects an error message.test_age_between_18_and_60tests valid ages including boundary values and expects a success message.test_age_greater_than_60tests an invalid high age and expects an error message.
Explicit waits ensure elements are ready before interaction. Locators use IDs for clarity and maintainability. Assertions check the exact expected messages to confirm correct behavior.
Now add data-driven testing with 3 different inputs for each partition (less than 18, valid range, greater than 60).
Practice
equivalence partitioning in software testing?Solution
Step 1: Understand equivalence partitioning concept
Equivalence partitioning divides input data into groups where all inputs in a group behave similarly.Step 2: Identify the main goal
The goal is to reduce the number of test cases by testing one value from each group instead of all values.Final Answer:
To divide input data into groups where test cases can be reduced -> Option CQuick Check:
Equivalence partitioning = reduce test cases [OK]
- Thinking it tests every input value
- Confusing with UI testing
- Assuming it is about coding tests
Solution
Step 1: Identify equivalence partitions
Partitions are: below valid range (<18), valid range (18-60), above valid range (>60).Step 2: Select test values from each partition
Choose one value from each: 17 (below), 18 and 60 (edges of valid), 30 (inside valid), 61 (above).Final Answer:
Test ages 17, 18, 30, 60, 61 -> Option AQuick Check:
Test one from each partition [OK]
- Testing only valid values
- Ignoring boundary values
- Testing too many values inside one partition
Solution
Step 1: Define partitions
Partitions are: below valid (<1), valid (1-100), above valid (>100).Step 2: Check which inputs cover all partitions
[0, 1, 50, 100, 101] includes 0 (below), 1 and 100 (edges valid), 50 (inside valid), 101 (above).Final Answer:
[0, 1, 50, 100, 101] -> Option BQuick Check:
Inputs cover all partitions [OK]
- Missing values outside valid range
- Testing only inside range
- Ignoring boundary values
Solution
Step 1: Identify partitions and errors
Partitions: below valid (<8), valid (8-12), above valid (>12). The original set misses some below and above values.Step 2: Fix test set to cover all partitions
[6, 8, 10, 12, 14] adds 6 (below), 14 (above), and includes valid 8, 10, 12, covering all partitions correctly.Final Answer:
[6, 8, 10, 12, 14] -> Option DQuick Check:
Test covers below, valid, and above partitions [OK]
- Missing values outside valid range
- Not testing boundary values
- Using only valid inputs
Solution
Step 1: Define partitions including decimals
Partitions: below valid (<0.0), valid (0.0 to 100.0), above valid (>100.0). Decimals allowed inside valid range.Step 2: Choose test inputs covering all partitions
[ -1, 0.0, 50.5, 100.0, 101 ] includes -1 (below), 0.0 (valid edge), 50.5 (valid decimal), 100.0 (valid edge), 101 (above).Final Answer:
[ -1, 0.0, 50.5, 100.0, 101 ] -> Option AQuick Check:
Test inputs cover all partitions including decimals [OK]
- Ignoring decimal values inside valid range
- Missing values outside valid range
- Testing only integers
Ready to prove it?
Pass the test and this pattern moves unknown
