liveBook · Manning

Integration test

As explained in Practices of the Python Pro

An integration test is a test that evaluates interactions between integrated software components or external systems.

An integration test checks whether multiple software units work together to produce useful behavior. Unlike a unit test, it exercises several methods or components; unlike an end-to-end workflow test, it focuses on code behavior rather than the user's perspective. section 5.2.5 section 5.4.4

Integration tests provide confidence that individually working pieces cooperate correctly, but they usually take longer and can be more tightly coupled to implementation details. Because they may involve databases or several operations, keep them fewer than unit tests and avoid chasing coverage when it makes tests brittle. section 5.2.5 section 5.7.2

Shopping cart integration

A useful test initializes a shopping cart, creates a product, adds it, removes it, and verifies that the cart is empty. This exercises the cart's initialization, product SKU generation, addition, and removal together: cart = ShoppingCart() product = Product('shoes', 'S', 'blue') cart.add_product(product) cart.remove_product(product) assert cart.products == {} section 5.4.4

Use integration tests to:

  • Check that dependent units exchange data and produce the intended combined behavior. section 5.2.5
  • Automate repeatable checks, then add tests for newly discovered ways the software might fail. section 5.2.6
  • Balance broad functional coverage against slower execution, brittle tests, and implementation coupling. section 5.2.5 section 5.7.2
Figure 5.3. Integration tests focus on how operations work together.

Use the integration-test diagram to distinguish coordinated operations from isolated unit behavior. section 5.2.5

How Practices of the Python Pro covers it

How deep it goes
Explains scope, trade-offs, and a multi-method Python example, while stopping short of detailed database or framework configuration.
Examples
Demonstrates a ShoppingCart test that adds and removes a Product, verifies an empty cart, and uses unittest.
What it assumes
Assumes familiarity with individual units and unit tests, while building from the distinction between isolated and integrated behavior.
What you can do after
Apply it via Python's unittest or pytest to verify several cooperating units and automate regression checks.
How it connects
Connects integration testing with unit testing, end-to-end testing, functional testing, test automation, testing pyramids, and test-driven development.

Also explained in

Compare how 31 books explain integration test →

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.