how to make a Python test driven development environment

what is Test Driven Development (TDD)?

Test Driven Development is a way to write software with a focus on tests. I write tests for ideas to reach a goal or meet a requirement, and the results tell me if I am closer to the goal or not. I repeat the process until I get to the goal.


what is a Test Driven Development Environment?

A Test Driven Development environment is a group of files and folders in a project where I can write tests and code and they automatically run so I see the results quickly.


what is the Test Driven Development cycle?

The Test Driven Development cycle is RED GREEN REFACTOR

  • RED: make it fail - I write a test that fails to make sure the test works

  • GREEN: make it pass - I write the simplest thing that will make the failing test pass

  • REFACTOR: make it better - I write a better solution, test or both, usually by removing duplication

This process can be repeated as many times as needed until I get to my goal.


preview

I set up an environment for every Python project, this way I keep all the things that belong to the project in the same place.

I can do this manually, which means I have to do the same steps for every project or I could do it automatically where I give the computer a command and it does all the steps for me.

Some things I think about when I want to start a project

  • What name will I give the project? this is based on what the project will do. Naming things is its own challenge

  • What is the structure of the project? - What files and folders does the project need?

  • What other programs does my project need?

  • What tests am I going to write for this project?

It turns out some of this is the same for every project

  • I give the project a name

  • I make a new folder for the project with the name I gave it

  • I try to name everything in the project with the name of the project or with something that describes what it does

  • I place the code for the project in a src folder

  • I place the tests for the project in a tests folder

  • I write what programs the project needs (its dependencies) in a requirements file

  • I make a virtual environment to keep the dependencies separate from the rest of the computer

  • I install what the project needs in the virtual environment

  • I work in the virtual environment

  • I run automated tests to make sure I have a Test Driven Development environment

  • I start writing code for the project

Here is what that structure looks like if the name of the project is PROJECT_NAME

PROJECT_NAME
├── .virtual_environment
├── requirements_file
├── src
   └── PROJECT_NAME.py
└── tests
    └── test_PROJECT_NAME.py

what is covered?

This is one way to make a Python Test Driven Development project. I walk through making the folders (directories) and files for the environment, including setting up the first test.

what is next?

You have seen me make a Test Driven Development environment for a project called magic on any Linux, MacOS and Windows_computers. Would you like to test AssertionError next?


rate pumping python

If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too