0
0
Testing Fundamentalstesting~20 mins

Test-driven development (TDD) concept in Testing Fundamentals - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
TDD Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the first step in the TDD cycle?

In Test-driven development (TDD), which step comes first in the cycle?

AWrite the minimal code to pass the test
BRefactor the existing code to improve structure
CWrite a failing test that defines a new function or feature
DRun all tests to ensure everything passes
Attempts:
2 left
💡 Hint

Think about what guides the development in TDD.

Predict Output
intermediate
2:00remaining
What is the output of this TDD test run?

Given the following Python test code using unittest, what will be the test result when run the first time?

Testing Fundamentals
import unittest

def add(a, b):
    pass  # Not implemented yet

class TestAdd(unittest.TestCase):
    def test_add_positive(self):
        self.assertEqual(add(2, 3), 5)

if __name__ == '__main__':
    unittest.main()
ATest passes successfully
BTest fails with AssertionError
CSyntaxError due to missing return
DTypeError because add() returns None
Attempts:
2 left
💡 Hint

What does the add function return currently?

assertion
advanced
1:30remaining
Which assertion best fits TDD for checking a list contains a new item?

You are writing a test first in TDD to check that a function adds an item to a list. Which assertion is the best choice?

Aself.assertIsNotNone(result_list)
Bself.assertEqual(result_list[-1], 'item')
Cself.assertListEqual(result_list, ['item'])
Dself.assertTrue('item' in result_list)
Attempts:
2 left
💡 Hint

Focus on what exactly you want to verify about the list.

🔧 Debug
advanced
2:00remaining
Why does this TDD test keep passing incorrectly?

In TDD, you wrote this test and function. The test passes but the function is clearly wrong. Why?

Testing Fundamentals
def is_even(n):
    return True

def test_is_even():
    assert is_even(3) == False
    assert is_even(4) == True
AThe test passes because assert statements are not executed when Python runs with optimizations
BThe function always returns True, so the test should fail but does not
CThe test uses assert statements outside a test framework, so failures are ignored
DThe test is not run because it lacks a test framework decorator
Attempts:
2 left
💡 Hint

Consider how Python treats assert statements when run with certain flags.

framework
expert
1:30remaining
Which test runner command fits TDD workflow for Python unittest?

In a TDD workflow using Python's unittest, which command runs tests and stops at the first failure to help quick feedback?

Apython -m unittest --failfast
Bpython -m unittest -f
Cpython -m unittest -v
Dpython -m unittest discover
Attempts:
2 left
💡 Hint

Look for the option that stops testing on first failure.