Test-Driven Development

You will be building a Notes app using a type of software development known as Test-Driven Development (TDD). Take a look at the following diagram, and the following explanation:

TDD is a software development method where tests are written before the actual program code.

RED: Red is the first stage of the TDD process. Here, you write tests. Since this is the first test, it means you basically have nothing to test. Therefore, you must write the minimum piece of code that you can test. Now, since it's the least amount of code required to be able to write a test, it will most likely fail when you write the code. But that's totally fine. In TDD, your tests must fail before anything else happens! When your tests fail, that's the first stage of the TDD cycle—the red stage.

GREEN: Now, you have to write the minimum piece of code required to pass the test. When the test passes, that's great, you have completed the second phase of the TDD cycle. Passing the test means that you have a part of your program working just as you expect it to. And as you keep building your app this way, at any point in time you will have every part of your code tested. Can you see how this works? By the time you have completed a feature, you have sufficient tests for testing various parts of that feature.

REFACTOR: The final stage of the TDD process is to refactor the code you wrote earlier to pass the test. Here, you remove redundant code, clean up, and write the full implementation for mocks. Afterwards, run the tests again. They may likely fail. In TDD, failing tests is a good thing. When you write tests and they pass, you can be certain a particular requirement or expectation has been met.

There are other forms of development models built around testing, such as Behavior-Driven Testing, black-box testing, and smoke testing. However, they can basically be categorized under functional testing and non-functional testing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset