Python Zero to Heros

Online Absolute Beginner Python Tutorials 

Every Sunday 2pm (UK time/ BST)

Get this slide deck:

slides.com/cheukting_ho/python-tdd

Recap

Python objects - int, float, str, list, dict, bool

Control flows - if-else, for loop, while loop

Functions, modeuls, classes and decorators

strings operations and regex with re

pytest with fixtures and mock

property-based testing

python linters & auto-formatters

 

Any Questions?

Recap:What is Unit test

 

unit testing is a software testing method by which individual units of source code... are tested to determine whether they are fit for use. - en.wikipedia.org/wiki/Unit_testing

 

First your program are structured in units: e.g. functions, classes, modules

Making sure a functions works as it is supposed to locks that pieces of code in place

Most basic piece of testing, to test everything we need other tests. e.g. integration testing, end-to-end testing etc

What is TDD?

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the code is improved so that the tests pass.

- wikipedia

 

Test-driven development cycle

  1. Add a test
  2. Run all tests and see if the new test fails
  3. Write the code
  4. Run tests
  5. Refactor code
  6. Repeat

 

TDD cycle

Pros of TDD

  • Codes are well structured and clean
  • Easy to maintain
  • Easy to document
  • Design in the users' perspective

😃

Cons of TDD

  • Time upfront to write tests
  • Short sighted
  • Refactoring may be a pain
  • Bad tests lead to false sense of secutity

😞

When to TDD?

When your task can be break down into isolated modules.

 

TDD lends itself really well to when you have a pure logic function that you need to write. When the work you need to do has a clearly defined set of expected inputs and outputs, it's a great signal that you should use TDD to build out your tests and code.

- https://blog.ncrunch.net/

To TDD

or not to TDD?

  1. If you are starting a project fresh, breakdown tasks in units and TDD
     
  2. Always add unit tests to exsting codebase (unless the code is not to be maintained)
     
  3. Don't be fustrated by writing tests

Let's TDD

Next week:
Term break?

Sunday 2pm (UK time/ BST)

There are also Mid Meet Py every Wednesday 1pm

Testing month in June

Python TDD

By Cheuk Ting Ho

Python TDD

  • 307
Loading comments...

More from Cheuk Ting Ho