Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to mark the 'Given' step in a pytest test function.
PyTest
def test_addition(): # [1]: Setup numbers a = 2 b = 3 result = a + b assert result == 5
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'Given' with 'When' or 'Then' steps.
✗ Incorrect
The 'Given' step sets up the initial context or data for the test.
2fill in blank
mediumComplete the code to mark the 'When' step where the action happens.
PyTest
def test_subtraction(): a = 5 b = 3 # [1]: Perform subtraction result = a - b assert result == 2
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Given' or 'Then' instead of 'When' for the action step.
✗ Incorrect
The 'When' step describes the action or event being tested.
3fill in blank
hardFix the error in the 'Then' step comment describing the expected outcome.
PyTest
def test_multiplication(): a = 4 b = 3 result = a * b # [1]: Check if result equals 12 assert result == 12
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Labeling the 'Then' step as 'When' or 'Given'.
✗ Incorrect
The 'Then' step verifies the expected result or outcome of the test.
4fill in blank
hardFill both blanks to complete the Given-When-Then comments in the test.
PyTest
def test_division(): # [1]: Setup numbers numerator = 10 denominator = 2 # [2]: Perform division result = numerator / denominator assert result == 5
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping 'Given' and 'When' labels.
✗ Incorrect
'Given' sets up the data, 'When' performs the action.
5fill in blank
hardFill all three blanks to complete the Given-When-Then pattern in the test function.
PyTest
def test_string_upper(): # [1]: Setup input string input_str = "hello" # [2]: Convert string to uppercase result = input_str.upper() # [3]: Verify the result is uppercase assert result == "HELLO"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of Given, When, Then.
✗ Incorrect
'Given' sets up data, 'When' performs action, 'Then' checks result.