liveBook · Manning

Testing pyramid

As explained in Django in Action

A testing pyramid is a model that organizes software tests into levels based on scope, speed, and execution cost.

The testing pyramid organizes automated tests by how much software they exercise. Start with focused tests for individual components, then test cooperation between components and finally verify required behavior. The exact shape varies: different teams use three to seven levels and different names. section 8.1.1

Figure 8.1 Hierarchy of testing categories
figure

Use the hierarchy diagram to compare testing categories by scope and see how the levels relate. section 8.1.1

The named levels describe increasingly broad checks:

  • Unit tests exercise one component, typically a single function. Keep them independent, minimize side effects, and make their results unaffected by execution order. section 8.1.1
  • Integration tests exercise several units together and check whether their cooperation produces the desired result. They may also be called system tests and usually stay at the business-logic or server level rather than the GUI. section 8.1.1
  • Behavioral tests map directly to requirements and verify that a feature performs its intended action. Acceptance tests is another common name, and Cucumber is a framework associated with this level. section 8.1.1
  • Django projects can also be tested at the user-interface level, although doing so requires more work than the unit and integration levels. section 8.7

A database side effect

A function-level test is easiest to keep independent when it avoids changing shared state. Writing to a database is a side effect, so deciding whether that behavior belongs in a unit test requires care; broader integration coverage may be more appropriate. section 8.1.1

How Django in Action covers it

How deep it goes
Defines unit, integration, and behavioral testing, then notes UI testing without detailing its implementation.
Examples
Uses a testing-category figure, single-function tests, database writes, Cucumber, and Django UI testing as concrete reference points.
What it assumes
Introduces automated-testing categories before moving into Python and Django test structure.
What you can do after
Evaluate which testing level matches a component, interaction, requirement, or user-interface concern.
How it connects
Connects unit testing with side effects, integration testing with business logic, behavioral testing with acceptance criteria, and UI testing with Django.

Also explained in

Compare how 8 books explain testing pyramid →

Related concepts

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