The Red Stage: Writing the Initial Tests

Learn how to implement the red stage of the TDD process.

In this lesson, we’ll learn how to implement the red stage of the TDD process. The goal of this stage is to write the initial tests that sufficiently cover the requirements we want to implement. However, we must remember that there is not yet any code to fulfill these requirements, and that all tests are expected to fail.

Initial requirements

We’ve been tasked with building an application that can convert text written in the Markdown (MD) format into HTML. Markdown is a popular documentation format used by most code repositories on GitHub. This format is more convenient and not as verbose as other options.

However, the downside is that browsers cannot directly interpret MD, which can only be displayed in its raw format. For example, rather than appear as intended by the user, the headings, bold text, etc., look like basic text surrounded by special characters in MD.

If we want to display our MD document in a browser, we must convert its content into HTML. This is what we will do for this task. However, we don’t need to handle all the special characters supported by MD for our first iteration. Our minimal viable product (MVP) should be able to do the following:

  • Convert MD paragraphs into HTML paragraphs surrounded by the <p> tag.

  • Convert the bold MD text, which is surrounded by the ** characters, into HTML bold text surrounded by the <strong> tag.

  • Convert the italic MD text, which is surrounded by the * characters, into HTML italic text surrounded by the <em> tag.

  • Convert the MD text with a strikethrough, which is surrounded by the ~~ characters, into HTML text with a strikethrough surrounded by the <del> tag.

  • Add a line break at the end using the <br> tag.

Get hands-on with 1200+ tech skills courses.