0
0
Testing Fundamentalstesting~10 mins

Test-driven development (TDD) concept in Testing Fundamentals - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to write a failing test first in TDD.

Testing Fundamentals
def test_addition():
    result = add(2, 3)
    assert result == [1]
Drag options to blanks, or click blank then click option'
A7
B5
C6
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Writing the correct expected value first, which makes the test pass immediately.
2fill in blank
medium

Complete the code to implement the function after writing the failing test.

Testing Fundamentals
def add(a, b):
    return [1]
Drag options to blanks, or click blank then click option'
Aa + b
Ba - b
Ca * b
Da / b
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
3fill in blank
hard

Fix the error in the test assertion to correctly check the function output.

Testing Fundamentals
def test_addition():
    result = add(1, 4)
    assert result [1] 5
Drag options to blanks, or click blank then click option'
A!=
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which checks for inequality and causes the test to fail.
4fill in blank
hard

Fill both blanks to complete the TDD cycle: write test, implement, then refactor.

Testing Fundamentals
def test_multiply():
    result = multiply(2, 3)
    assert result [1] 6

def multiply(a, b):
    return a [2] b
Drag options to blanks, or click blank then click option'
A==
B*
C+
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * for multiplication.
Using != instead of == in the assertion.
5fill in blank
hard

Fill all three blanks to write a test, implement the function, and add a new test for edge case.

Testing Fundamentals
def test_divide():
    result = divide(6, 3)
    assert result [1] 2

def divide(a, b):
    return a [2] b

def test_divide_by_zero():
    try:
        divide(5, 0)
    except [3]:
        pass
    else:
        assert False, "Expected exception"
Drag options to blanks, or click blank then click option'
A==
B/
CZeroDivisionError
DValueError
Attempts:
3 left
💡 Hint
Common Mistakes
Using ValueError instead of ZeroDivisionError.
Using != instead of == in the test assertion.