liveBook · Manning

Test log pattern

As explained in Effective Behavior-Driven Development

A test-automation pattern that records structured execution details across automation layers to support failure diagnosis.

An assertion tells you where a scenario stopped, but not necessarily what caused the failure. The Test Log pattern records what the automation did before that point, making the path to the error easier to follow. section 19.3 section 19.7

Start with the boundary between the test layer, which decides what actions to take, and the automation layer, which performs them. Log each action’s name, inputs, result, and duration. A shared test-action implementation can record these details consistently instead of relying on scattered log statements. section 19.3

A login that needs more than a pass or fail

A login log records the attempted action, a masked password, and the returned result. When deeper detail is needed, it can also show the REST API request and response made during that action. Together, those entries distinguish the scenario’s intended action from the lower-level interaction that carried it out. section 19.3

Listing 19.9 Hierarchical test execution log
*** Test execution result (lines trimmed for readability) ***
When the customer attempts to log in with valid password
  18:52:15 Info: Executing Login with (Rebecca, ****)...
    18:52:15 Debug: REST API request: POST /api/auth/login, Content:... 
    18:52:15 Debug: REST API response: 200 (OK), Content:... 
  18:52:15 Info: Login executed successfully in 00:00:00.2476439 with... 
-> done: AuthenticationStepDefinitions.WhenTheCustomerAttemptsToLogIn...
Then they should be authenticated
-> done: AuthenticationStepDefinitions.ThenTheyShouldBeAuthenticated...

The hierarchical log nests REST API entries under the login action, so the order and relationship of events remain visible. section 19.3

Keep the default log useful rather than exhaustive: excess detail can obscure important events and consume storage. Adjust detail through configuration or feature-file tags when diagnosis calls for more. Application log entries can provide further context, but the test log’s central job is to show the flow of test automation. section 19.7

How Effective Behavior-Driven Development covers it

How deep it goes
Explains where to log across automation layers, illustrates action and REST API entries, and shows hierarchical presentation and detail controls.
Examples
Uses a customer login scenario, masked credentials, action results, REST API exchanges, and a nested execution log.
What it assumes
Assumes BDD scenarios with step definitions and layered automation, then identifies the boundary where logging is most useful.
What you can do after
Build it from scratch by logging action boundaries and presenting related lower-level events as a readable execution history.
How it connects
Connects BDD scenarios and test actions to REST API logging, descriptive assertions, supplementary attachments, and embedded application logs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.