You are on page 1of 5

Testing tip - focus testing efforts on testing private

methods

Testing tip:

Focus the majority of your testing efforts on testing methods that you (or other
stakeholders) intend to call from other packages/modules. Everything else is just an
implementation detail.

tdd
Posted on Twitter on March 8, 2022.

Testing tip - use mocks only when necessary

Testing tip:

Use mocks only when necessary (like for third-party HTTP APIs). They make your test
setup more complicated and your tests overall less resistant to refactoring.

Plus, they can result in false positives.

tdd
Posted on Twitter on March 7, 2022.

Writing Valuable Tests

Testing tip:

A test is valuable only when it protects you against regressions, allows you to refactor,
and provides you with fast feedback.

tdd
Posted on Twitter on March 5, 2022.

Testing tip - create more loosely coupled


components and modules

Testing tip:

There's no single right way to test your software.

Nonetheless, it's easier and faster to test logic when it's not coupled with your database.

tdd
Posted on Twitter on March 1, 2022.

Python Testing - Given When Then syntax

TDD tip:

You can add GIVEN, WHEN, THEN as a docstring to your tests to better express your
intent.

An example👇

def test_all(self):
        """
        GIVEN a PhoneBook with a records property
        WHEN the all method is called
        THEN all numbers should be returned in ascending order
        """
        phone_book = PhoneBook(
                records=[
                        ("John Doe", "03 234 567 890"),
                        ("Marry Doe", "01 234 567 890"),
                        ("Donald Doe", "02 234 567 890"),
        ]
    )

        previous = ""

        for record in phone_book.all():


                assert record[0] > previous
                previous = record[0]

tdd
Posted on Twitter on Feb. 23, 2021.

Test-diven devopment and pair programming

TDD Tip:

When practicing Test-driven Development with pair programming, try having one
developer write the failing test while the other writes the code to get it to pass. The first
developer is the responsible for any refactoring.

Why?

1 It's fun.
2 This can accelerate the learning of a less experienced developer when paired with a more
experienced developer.
For more TDD benefits, check out What is Test-Driven Development? .

tdd
Posted on Twitter on Jan. 22, 2021.

FILTER BY TOPIC
Show All
Django
Docker
FastAPI
Flask
Pytest
Python
TDD

LEARN
Courses
Bundles
Blog
GUIDES
Complete Python
Django and Celery
Deep Dive Into Flask
ABOUT TESTDRIVEN.IO
Support and Consulting
What is Test-Driven Development?
Testimonials
Open Source Donations
About Us
Meet the Authors
Tips and Tricks
TestDriven.io is a proud supporter of open source
10% of profits from each of our FastAPI courses and our Flask Web Development course will be donated to the
FastAPI and Flask teams, respectively.

Follow our contributions


© Copyright 2017 - 2023 TestDriven Labs.Developed by Michael Herman.

You might also like