This test checks that a previously fixed bug does not appear again after new changes. It verifies that the login feature still works correctly after updates.
Test Code - Selenium with unittest
Testing Fundamentals
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 TestLoginRegression(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.get('https://example.com/login')
def test_login_functionality(self):
driver = self.driver
# Wait for username field
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'username')))
username_input = driver.find_element(By.ID, 'username')
password_input = driver.find_element(By.ID, 'password')
login_button = driver.find_element(By.ID, 'login-btn')
username_input.send_keys('testuser')
password_input.send_keys('correctpassword')
login_button.click()
# Wait for dashboard to load
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'dashboard')))
dashboard = driver.find_element(By.ID, 'dashboard')
self.assertTrue(dashboard.is_displayed(), 'Dashboard should be visible after login')
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
Execution Trace - 8 Steps
Step
Action
System State
Assertion
Result
1
Test starts and opens Chrome browser
Browser opened at https://example.com/login page
—
PASS
2
Waits up to 10 seconds for username input field to appear
Login page loaded with username, password fields and login button visible
Username input field is present
PASS
3
Finds username, password inputs and login button elements
All login form elements located
—
PASS
4
Enters 'testuser' in username and 'correctpassword' in password fields
Login form filled with credentials
—
PASS
5
Clicks the login button
Login form submitted, waiting for dashboard page
—
PASS
6
Waits up to 10 seconds for dashboard element to appear
Dashboard page loaded with dashboard element visible
Dashboard element is present
PASS
7
Checks if dashboard element is displayed
Dashboard visible on screen
Assert dashboard.is_displayed() is True
PASS
8
Test ends and browser closes
Browser closed
—
PASS
Failure Scenario
Failing Condition: Dashboard element does not appear after login, indicating login failed or page did not load
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the dashboard page appears
BThat the login button is disabled
CThat the username field is cleared
DThat the password is visible
Key Result
Always include checks for key page elements after a change to confirm old features still work, which is the core of regression testing.
Practice
(1/5)
1.
What is the main purpose of regression testing in data science projects?
easy
A. To check that new changes do not break existing results
B. To create new models from scratch
C. To collect new data for training
D. To visualize data trends
Solution
Step 1: Understand regression testing goal
Regression testing is about verifying that recent changes do not cause errors in existing functionality.
Step 2: Match purpose with options
Only To check that new changes do not break existing results describes this goal correctly, others describe unrelated tasks.
Final Answer:
To check that new changes do not break existing results -> Option A
Quick Check:
Regression testing = check no breakage [OK]
Hint: Regression testing ensures old results still work after changes [OK]
Common Mistakes:
Confusing regression testing with model building
Thinking it collects new data
Assuming it is for data visualization
2.
Which of the following is the correct way to describe regression testing?
old_results has [10, 20, 30], new_results has [10, 20, 25]. The last elements differ (30 vs 25).
Step 2: Evaluate the if condition
Since the lists are not equal, the else block runs, printing "Test Failed".
Final Answer:
Test Failed -> Option C
Quick Check:
Lists differ, so output = Test Failed [OK]
Hint: Lists must match exactly for test to pass [OK]
Common Mistakes:
Assuming partial match passes test
Confusing list equality with set equality
Expecting syntax errors from correct code
4.
Identify the error in this regression testing code snippet:
def regression_test(old, new):
if old = new:
return True
else:
return False
medium
A. Missing return statement
B. Using assignment operator '=' instead of comparison '==' in if condition
C. Function should print results, not return
D. Incorrect function name
Solution
Step 1: Check the if condition syntax
The condition uses '=' which is assignment, not comparison. Python requires '==' for comparison.
Step 2: Identify correct syntax for comparison
Replacing '=' with '==' fixes the syntax error and allows proper comparison.
Final Answer:
Using assignment operator '=' instead of comparison '==' in if condition -> Option B
Quick Check:
Use '==' to compare, not '=' [OK]
Hint: Use '==' for comparison, '=' is assignment [OK]
Common Mistakes:
Confusing '=' and '==' in conditions
Thinking return is missing
Believing function name matters for syntax
5.
You have a data science model that outputs predictions as a list. You want to automate regression testing to check if new code changes break the model's output. Which approach below best applies regression testing?
hard
A. Delete old predictions and start fresh after every change
B. Train a new model with updated data and ignore old predictions
C. Visualize new predictions only to check for differences
D. Save previous predictions and compare them with new predictions after changes
Solution
Step 1: Understand regression testing in model outputs
Regression testing means re-running tests and comparing new outputs to old outputs to detect unintended changes.
Step 2: Evaluate options for best fit
Save previous predictions and compare them with new predictions after changes saves old predictions and compares them to new ones, matching regression testing. Others ignore old outputs or delete them, which is not regression testing.
Final Answer:
Save previous predictions and compare them with new predictions after changes -> Option D
Quick Check:
Regression testing = compare old and new outputs [OK]
Hint: Keep old outputs to compare with new after changes [OK]
Common Mistakes:
Ignoring old outputs in testing
Assuming visualization replaces regression tests
Deleting old results before testing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.