liveBook · Manning

Dependent test

As explained in Test Driven: Practical TDD and Acceptance TDD for Java Developers

A test whose execution or expected outcome depends on state or results produced by another test.

A dependent test relies on state or results produced by another test. Dependencies can arise when a test suite performs expensive setup once, rather than repeating it before every test. section 11.4.1

Shopping cart and sales statistics

Suppose one test checks successful purchases and creates orders in a database. A later test checks sales statistics using those orders. If the purchase test changes the orders it creates, the statistics test may need to change too. section 11.4.1

Sharing setup can speed up execution, but dependencies make tests harder to maintain. One failure can also trigger failures in dependent tests, making it harder to identify which failures have their own causes. section 11.4.1

Figure 11.15. With ordered, dependent tests, we can perform a common setup just once in the beginning of the test suite. However, each test case may have assumptions about the side effects of earlier tests.

The diagram shows ordered tests sharing one setup and relying on earlier tests’ side effects. section 11.4.1

How Test Driven: Practical TDD and Acceptance TDD for Java Developers covers it

How deep it goes
Explains a shared-setup sequence and its maintenance and reporting trade-offs without specifying an implementation.
Examples
Uses shopping-cart purchases that create orders for a later sales-statistics test.
What you can do after
Evaluate whether shared setup is worth the maintenance and failure-reporting costs.
How it connects
Connects test setup, shared state, test ordering, and failure reporting.

This explainer was generated by Manning's knowledge graph from the text of Test Driven: Practical TDD and Acceptance TDD for Java Developers. The section links point to the parts of the book it draws on.