In Test-driven development (TDD), which step comes first in the cycle?
Think about what guides the development in TDD.
The TDD cycle starts by writing a test that fails because the feature is not implemented yet. This test defines what the code should do.
Given the following Python test code using unittest, what will be the test result when run the first time?
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()
What does the add function return currently?
The add function is not implemented and returns None by default. The test expects 5, so the assertion fails.
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?
Focus on what exactly you want to verify about the list.
Using assertTrue with 'in' checks that the item is present anywhere in the list, which is the most direct and flexible check for this case.
In TDD, you wrote this test and function. The test passes but the function is clearly wrong. Why?
def is_even(n): return True def test_is_even(): assert is_even(3) == False assert is_even(4) == True
Consider how Python treats assert statements when run with certain flags.
When Python runs with the -O (optimize) flag, assert statements are skipped, so the test does not fail even if the function is wrong.
In a TDD workflow using Python's unittest, which command runs tests and stops at the first failure to help quick feedback?
Look for the option that stops testing on first failure.
The --failfast option stops the test run immediately after the first failure, which is useful in TDD for fast feedback.