...

/

The Refactor Stage: Cleaning Up the Code

The Refactor Stage: Cleaning Up the Code

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

The process of refactoring involves optimizing the design of the code without changing its behavior. In TDD, this is the final stage of the process. We conduct it when we already have the tests written and some quick solutions implemented to make the relevant tests pass.

Press + to interact

Implementing the refactor stage

The following playground represents a setup at the point when the green stage of TDD is complete. It contains a class called MdToHtmlConverter, which further contains the ConvertText() method with a limited capability of converting MD text into HTML.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>
Green stage implementation

On line 8, this method produces the intended output. We also have tests against it, which pass. However, the ...