liveBook · Manning

Functional testing

As explained in Practices of the Python Pro

A functional test evaluates software behavior by supplying input, determining expected output, obtaining actual output, and comparing the results.

Functional testing checks whether software produces the expected output for a given input. A test follows a simple recipe: prepare inputs, identify the expected output, obtain the actual output, and compare the two. Because this structure describes how code should behave, a good test can also serve as practical documentation. section 5.1.2

Apply the recipe at different scales:

  • For a function, give calculate_mean the list [1, 2, 3, 4] and expect 2.5. section 5.1.2
  • For an application workflow, add product 53-DE-232 to a cart and expect the product to appear there. section 5.1.2
  • Use unit and integration tests liberally, while treating long, brittle, or manual tests more conservatively. section 5.2.6

Testing a product transformation

With Python's unittest, create Product('shoes', 'S', 'black'), set the expected value to 'SHOES', call transform_name_for_sku(), and compare the result with assertEqual(expected_value, actual_value). A failing assertion reports the differing values, helping locate the defect. Extend the same pattern to color transformation, SKU generation, cart state, and edge cases such as removing more products than the cart contains. section 5.4.3 section 5.4.6

Figure 5.1. The basic flow of a functional test

Use the flow diagram to scan the relationship between inputs, expected output, actual output, and comparison. section 5.1.2

How Practices of the Python Pro covers it

How deep it goes
Defines four test steps, demonstrates Python implementation, and compares unit, integration, manual, and performance testing without low-level internals.
Examples
Uses mean calculation, e-commerce cart behavior, product SKU transformations, shopping-cart assertions, and an over-removal edge case.
What it assumes
Assumes enough Python to create objects, call methods, and run a test command, while teaching the functional-test recipe explicitly.
What you can do after
Apply it via unittest or pytest to write assertions, detect failures, test alternate outcomes, and build confidence incrementally.
How it connects
Connects functional testing with unit testing, integration testing, manual testing, performance testing, and test-driven development.

Also explained in

Compare how 2 books explain functional testing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.