Run the Test

Follow step-by-step instructions to run the tests in test-driven development.

The second step involved in the TDD process is to run the tests. These tests must be the actual tests we write in step one of the test-driven development process because those tests must fail. After all, the feature hasn’t been built. In addition, it’s also important that the tests we run are properly testing what’s meant to be tested—a new feature yet to be implemented. Therefore, in this step, it’s recommended that we don’t run old tests that have been written earlier. This will come later when we want to make all tests pass.

How does it work?

Recall those sample tests we saw in the previous lesson. Please bear in mind that they’re only for illustration purposes. A more practical example is shown in the next chapter when we start to build the project for this course.

There are four sample tests: test_user_profile_contains_correct_html, test_user_profile_template test_user_profile_ test_create_user_profile`.

These tests can be run in the following way:

python manage.py test

We can also run them using Docker in the following way:

docker-compose exec web python manage.py test

The tests would fail since the feature is not yet implemented. The output would be something similar to this:

...
Ran 4 test in 0.030s

FAILED (errors=4)
Destroying test database for alias 'default'...

Working example

Here’s an example:

Get hands-on with 1200+ tech skills courses.