200-901 Question 10
Select 3A development team is building a new API and decides to implement test-driven development (TDD). Which of the following steps correctly describe the TDD workflow?
- A
Write a failing test case for the desired functionality.
- B
Write the full implementation of the feature before writing tests.
- C
Refactor the code after making the test pass.
- D
Ensure all tests pass before moving to the next feature.
- E
Skip writing tests for trivial features to save time.
Show answer and explanation
Correct answers: A, C, D
Explanation
Test-driven development (TDD) is a software development process where tests are written before the actual implementation. The workflow involves writing a failing test case, writing just enough code to make the test pass, and then refactoring the code for improvement while ensuring the test still passes. This iterative process ensures high-quality code and comprehensive testing.
- A. Correct.
Correct: In TDD, you start by writing a test case for the functionality you want to implement, ensuring it fails initially because the feature is not yet implemented.
- B. Incorrect.
Incorrect: TDD emphasizes writing tests before implementing the feature. Writing the full implementation before tests violates the TDD process.
- C. Correct.
Correct: After making the test pass, TDD encourages refactoring to improve code quality while ensuring the test still passes.
- D. Correct.
Correct: Ensuring all tests pass is critical in TDD to maintain confidence in the codebase before moving forward.
- E. Incorrect.
Incorrect: Skipping tests, even for trivial features, can lead to untested code and potential bugs. TDD advocates testing all aspects of the code.