Challenge - 5 Problems
Arrange-Act-Assert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Identify the output of a pytest test using Arrange-Act-Assert
What will be the result of running this pytest test function?
PyTest
def add(a, b): return a + b def test_add(): # Arrange x = 5 y = 3 # Act result = add(x, y) # Assert assert result == 8
Attempts:
2 left
💡 Hint
Check if the assertion matches the expected sum of x and y.
✗ Incorrect
The test arranges inputs x=5 and y=3, acts by calling add(x, y), and asserts the result equals 8. Since 5 + 3 is 8, the assertion passes and the test succeeds.
❓ assertion
intermediate2:00remaining
Choose the correct assertion for Arrange-Act-Assert pattern
Given the following test code snippet, which assertion correctly verifies the output?
PyTest
def multiply(a, b): return a * b def test_multiply(): # Arrange a = 4 b = 6 # Act output = multiply(a, b) # Assert # Which assertion is correct here?
Attempts:
2 left
💡 Hint
Multiply 4 by 6 and check the expected result.
✗ Incorrect
4 multiplied by 6 equals 24, so the assertion should check output == 24 to pass.
🔧 Debug
advanced2:00remaining
Find the bug in this Arrange-Act-Assert pytest test
This test is supposed to check if the function returns the square of a number. What is the bug causing the test to fail?
PyTest
def square(n): return n * n def test_square(): # Arrange num = 7 # Act result = square(num) # Assert assert result == 42
Attempts:
2 left
💡 Hint
Calculate 7 squared and compare with the assertion value.
✗ Incorrect
7 squared is 49, but the assertion expects 42, causing the test to fail.
❓ framework
advanced2:00remaining
Identify the correct Arrange-Act-Assert structure in pytest
Which of the following pytest test functions correctly follows the Arrange-Act-Assert pattern?
Attempts:
2 left
💡 Hint
Arrange means setting up variables first, then Act, then Assert last.
✗ Incorrect
Option A arranges variables x and y, acts by adding them, then asserts the result. Others mix steps or assert too early.
🧠 Conceptual
expert2:00remaining
Why is the Arrange-Act-Assert pattern important in testing?
Select the best explanation for the importance of the Arrange-Act-Assert pattern in writing tests.
Attempts:
2 left
💡 Hint
Think about how clear structure helps when reading or fixing tests later.
✗ Incorrect
Arrange-Act-Assert separates setup, action, and checking, making tests easier to understand and maintain.