Chapter 39. Importance of Test-Driven Development for Coders
Let`s discuss the importance of test-driven development. First and foremost, if the terms TDD or BDD, which are short for test- and behavior-driven development, are foreign to you, they are the practice of building code tests for applications.
And even more specifically, TDD and BDD are software development processes in which you create a test that sets an expectation before implementing any code.
An example of using TDD to create a feature for returning a full name from a user class would be to:
- Create a test that calls a new method, such as
full_name
, that combines the first and last name of a user and returns a string combining the names into a single value: - Then we'd run the test, knowing that it will fail:
- Then we would go and add a barebones implementation of the code:
This will get the test passing:
- Then we'd go back and refactor the implementation to ensure it conforms to best practices and that the refactor...