Search⌘ K

Write the Actual Code

Explore how to write the simplest code that allows your tests to pass during test-driven development in Django. Understand that the goal is to meet test requirements, not perfection, allowing for later refactoring. This lesson guides you through coding basics aligned with tests for templates, views, URLs, and models.

In this step, we must write the simplest code that would allow those tests to pass. The code written may not be the perfect code, but it can be refactored later. In fact, refactoring is part of the steps involved in TDD. In short, during this step, we shouldn’t aim to write the best code. Our aim should be to write the simplest code that passes when the test is rerun.

How does it work

Recall the four tests we introduced in step one. They’re just for demonstration purposes to explain the steps involved in test-driven development.

These tests are as follows:

  • test_user_profile_contains_correct_html
...