0
0
PyTesttesting~5 mins

Single responsibility per test in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does 'single responsibility per test' mean in software testing?
It means each test should check only one specific behavior or feature. This makes tests easier to understand and fix when they fail.
Click to reveal answer
beginner
Why is it better to have one assertion per test?
Having one assertion per test helps quickly find what went wrong. If a test fails, you know exactly which part of the code has a problem.
Click to reveal answer
intermediate
Example of a bad test violating single responsibility principle:
A test that checks if a user can log in and also if the user profile loads correctly. These should be two separate tests.
Click to reveal answer
intermediate
How does single responsibility per test help with test maintenance?
When tests focus on one thing, it's easier to update or fix them if the related feature changes. It reduces confusion and errors.
Click to reveal answer
beginner
In pytest, how can you organize tests to follow single responsibility?
Write small test functions each testing one behavior. Use clear names describing what each test checks.
Click to reveal answer
What is the main benefit of having a single responsibility per test?
AAllows multiple features to be tested together
BRuns tests faster
CEasier to find the cause of failure
DReduces the number of tests needed
Which of these violates the single responsibility principle in testing?
ATest login functionality only
BTest logout functionality only
CTest password reset separately
DTest user registration and profile update in one test
In pytest, how should you name tests to support single responsibility?
AUse descriptive names like test_login_with_valid_credentials
BUse generic names like test_feature
CUse numbers like test1, test2
DUse long paragraphs as names
What happens if a test has multiple responsibilities and fails?
AYou may need to debug multiple features
BYou immediately know the exact problem
CThe test will always pass
DThe test will run faster
Which practice helps maintain tests better?
ACombining many checks in one test
BWriting one test per feature or behavior
CSkipping tests for small features
DWriting tests without assertions
Explain why single responsibility per test is important and how it improves test quality.
Think about how you find problems faster when tests focus on one thing.
You got /4 concepts.
    Describe how you would write pytest functions to follow the single responsibility principle.
    Imagine each test as a small story about one feature.
    You got /4 concepts.