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:
full_name
, that combines the first and last name of a user and returns a string combining the names into a single value:This process is known as the Red, Green, Refactor workflow and is a pretty standard practice across all languages and frameworks.
With that dead simple explanation of how TDD works, let's discuss the importance of TDD and the best way to answer this coding interview question.
There's quite a bit of debate on the topic, with a number of prominent developers who are against the practice of TDD, with one of the main arguments being that many coders don't use it properly and are essentially just testing pre-existing functionality instead of behavior unique to the application.
However, with that being said, if you're looking to get hired as a developer there is a very good chance that you will need to be fully versed in how to work with TDD and BDD since I don't know of very many software organizations that don't require tests.
There are four main reasons why I use TDD for all the production applications that I build or manage:
For example, if I create a new method that will break if any nil values are passed to it and I call that method on legacy data that could contain some nil values, I want to know that before the new feature goes live. Without tests, I'd have to go and manually test every part of the application each time I implement a new piece of functionality. However, if I have a full test suite I can simply run the tests, and if they're all passing it is a good indicator that the new changes can be pushed live.
One caveat to TDD is that testing is pointless if the test suite is not well structured. If you simply create a myriad of tests that do nothing more than test the core functionality of a language or framework, your test suite isn't going to have any benefit. However, if you build an application and let the tests drive your development and code structure, you will end up with a great application that you should be proud of.
For further information, I recommend reading the full series by Martin Fowler, which is seen as one of the most in-depth discussions on TDD ever produced.
3.141.24.134