Imagine you have a big software project with thousands of tests but limited time to run them all before a release. Why is test prioritization important in this situation?
Think about which tests give the best value early.
Prioritizing tests helps find bugs earlier by running the most important or risky tests first, which saves time and improves software quality.
Given the following test cases with priorities, what is the order of test execution?
tests = [
{'name': 'LoginTest', 'priority': 2},
{'name': 'PaymentTest', 'priority': 1},
{'name': 'SignupTest', 'priority': 3},
{'name': 'ProfileTest', 'priority': 2}
]
# Tests run in ascending order of priority (1 is highest)
execution_order = [test['name'] for test in sorted(tests, key=lambda x: x['priority'])]
print(execution_order)Lower priority number means higher priority.
The tests are sorted by their priority number ascending: 1 (PaymentTest), 2 (LoginTest, ProfileTest), 3 (SignupTest).
You want to write an assertion to check that only tests with priority 1 or 2 are selected for execution. Which assertion is correct?
selected_tests = [
{'name': 'LoginTest', 'priority': 2},
{'name': 'PaymentTest', 'priority': 1},
{'name': 'SignupTest', 'priority': 3}
]
# Which assertion below correctly verifies all selected tests have priority 1 or 2?Use all() and check membership with in.
Option A correctly checks that every test's priority is either 1 or 2. Option A uses any() which only requires one test to match. Option A and D have logical errors.
What is the bug in this Python code that tries to prioritize tests by priority but fails?
tests = [
{'name': 'TestA', 'priority': 3},
{'name': 'TestB', 'priority': 1},
{'name': 'TestC', 'priority': 2}
]
# Attempt to sort tests by priority
sorted_tests = sorted(tests, key=lambda test: test.priority)
print([t['name'] for t in sorted_tests])Check how dictionary keys are accessed in Python.
Dictionaries use bracket notation with keys as strings, not dot notation. Using test.priority causes an AttributeError.
You want to integrate test prioritization in your Continuous Integration (CI) pipeline to run critical tests first. Which approach is best?
Think about automation and maintainability in CI.
Tagging tests by priority and configuring CI to run high-priority tests first is a scalable and automated way to prioritize tests in CI pipelines.