Testing vs debugging distinction in Testing Fundamentals - Automation Approaches Compared
import unittest 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 class CalculatorTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://localhost:8000/calculator') # Example URL def test_addition(self): driver = self.driver # Enter first number input1 = driver.find_element(By.ID, 'input1') input1.clear() input1.send_keys('5') # Enter second number input2 = driver.find_element(By.ID, 'input2') input2.clear() input2.send_keys('3') # Click Add button add_button = driver.find_element(By.ID, 'add-btn') add_button.click() # Wait for result to appear wait = WebDriverWait(driver, 10) result_element = wait.until(EC.visibility_of_element_located((By.ID, 'result'))) # Assert the result is '8' result_text = result_element.text self.assertEqual(result_text, '8', f'Expected result to be 8 but got {result_text}') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
This test script uses Python's unittest framework with Selenium WebDriver to automate the calculator addition test.
setUp() opens the browser and navigates to the calculator page.
test_addition() enters the numbers 5 and 3, clicks the Add button, waits explicitly for the result element to appear, then asserts the displayed result equals '8'.
Explicit waits ensure the test waits for the result instead of using fixed delays.
Locators use By.ID for clarity and maintainability.
tearDown() closes the browser after the test.
This clear separation of test steps and assertions helps distinguish testing (checking the result) from debugging (fixing issues if the test fails).
Now add data-driven testing with 3 different pairs of numbers to verify addition works for all.
Practice
testing in software development?Solution
Step 1: Understand the role of testing
Testing is about running the software to check if it behaves correctly and to find any bugs.Step 2: Differentiate testing from debugging
Debugging is about finding and fixing the cause of bugs, not just finding them.Final Answer:
To find bugs by checking if the software works as expected -> Option AQuick Check:
Testing = Find bugs [OK]
- Confusing testing with fixing bugs
- Thinking testing creates new features
- Mixing testing with design tasks
debugging?Solution
Step 1: Define debugging
Debugging means investigating the cause of bugs and correcting them in the code.Step 2: Compare with other options
Running tests is testing, not debugging. Writing features and designing tests are different tasks.Final Answer:
Finding and fixing the cause of bugs -> Option BQuick Check:
Debugging = Fix bugs [OK]
- Confusing debugging with testing
- Thinking debugging is writing new code
- Mixing debugging with test design
Solution
Step 1: Identify the testing result
The test found a crash when clicking a button, indicating a bug.Step 2: Understand debugging action
Debugging means analyzing the code to find the cause of the crash and fix it.Final Answer:
Analyze the code to find why the crash happens -> Option CQuick Check:
Debugging = Analyze and fix bug [OK]
- Continuing testing without fixing bugs
- Ignoring bugs found during testing
- Changing unrelated UI elements
Solution
Step 1: Identify debugging task
Debugging involves checking error messages and tracing code to find the cause of crashes.Step 2: Eliminate incorrect options
Running tests finds bugs but does not fix them. Writing features or ignoring crashes are wrong.Final Answer:
Check the error message and trace the code causing the crash -> Option DQuick Check:
Debugging = Trace and fix errors [OK]
- Confusing testing with debugging
- Skipping error analysis
- Adding features before fixing bugs
Solution
Step 1: Understand testing role
Writing a test case for the specific input helps reproduce and confirm the bug.Step 2: Understand debugging role
Debugging the code to fix the crash addresses the root cause of the bug.Step 3: Combine testing and debugging
Both steps together ensure the bug is found, fixed, and verified.Final Answer:
Write a test case for that input and then debug the code to fix the crash -> Option AQuick Check:
Test to find + Debug to fix = Correct approach [OK]
- Skipping test case creation for bugs
- Fixing bugs without verifying
- Ignoring problematic inputs
Ready to prove it?
Pass the test and this pattern moves unknown
