0
0
PyTesttesting~5 mins

Given-When-Then pattern in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the 'Given' step represent in the Given-When-Then pattern?
The 'Given' step sets up the initial context or preconditions for the test. It describes the starting state before the action happens.
Click to reveal answer
beginner
Explain the 'When' step in the Given-When-Then pattern.
The 'When' step describes the action or event that triggers the behavior you want to test.
Click to reveal answer
beginner
What is the purpose of the 'Then' step in the Given-When-Then pattern?
The 'Then' step checks the expected outcome or result after the action in the 'When' step. It contains assertions to verify the behavior.
Click to reveal answer
intermediate
How can you structure a pytest test function using Given-When-Then?
You can write comments or separate code blocks for Given (setup), When (action), and Then (assertions) inside a pytest test function to clearly show each step.
Click to reveal answer
beginner
Why is the Given-When-Then pattern helpful in writing tests?
It makes tests easier to read and understand by clearly separating setup, action, and verification. This helps communicate test intent like a story.
Click to reveal answer
In the Given-When-Then pattern, what does 'When' represent?
AThe cleanup after the test
BThe initial setup or context
CThe expected result or assertion
DThe action or event being tested
Which step in Given-When-Then contains assertions?
AGiven
BWhen
CThen
DSetup
How should you organize a pytest test using Given-When-Then?
AUse comments or separate blocks for Given, When, Then
BPut all code in one block without comments
COnly write assertions without setup
DWrite multiple test functions for each step
What is the main benefit of using Given-When-Then in tests?
AImproves test readability and understanding
BHelps tests look more complex
CRemoves the need for assertions
DMakes tests run faster
In pytest, which keyword is used to write a test function following Given-When-Then?
Aclass
Bdef
Cimport
Dassert
Describe the Given-When-Then pattern and how you would apply it in a pytest test function.
Think of it as telling a simple story in your test.
You got /4 concepts.
    Why is it important to separate test steps into Given, When, and Then?
    Imagine explaining your test to a friend.
    You got /4 concepts.