Results

test.Execute() returns a detailed result and a boolean that indicates whether the complete pipeline met its expectations.

The result retains the response and comparison of each step. It can be explained in the terminal, stored in files or included in the detailed output of Execution.


Execute

gox
result, match := test.Execute(config, pipeline)

match is true when all the steps match. result contains the information necessary to know what was executed and why a comparison failed.


Pass

test.Pass() records one or more successful messages.

gox
if match {
	test.Pass("La sesión se conservó durante todo el pipeline")
}

The messages appear below the result of the function.


Fail

test.Fail() records a failure and makes the function reported as FAIL.

gox
if !match {
	test.Fail("La respuesta no cumple el contrato")
}

It can be used to assess additional conditions that are not part of the expectations.


Explain

test.Explain() generates a legible explanation when the result contains differences.

gox
test.Explain(result)

The explanation may include:

  • Status code expected and received.
  • Absent headers or cookies and different values.
  • Fragments found or absent in the body.
  • First difference between texts.
  • Routes and JSON values that don't match.
  • Error or result received from an Action.

The extensive bodies are summarized to keep the output readable.


Save

test.Save() writes the individual result as JSON within tests/results/.

gox
test.Save(result)

In test mode also creates a folder responses/ together with the result and save an HTTP representation of each response. These files allow you to review the full status code, headers, cookies and body.

During a Benchmark, Save() retains the JSON metrics, but does not generate response devices.


Results per step

Each step may include:

InformationDescription
ContentsPosition inside the pipeline.
TypeHTTP, Action or error request.
Method and URLOperation executed.
ResponseResponse captured.
StatusStatus code comparison.
HeadersComparison of headers.
CookiesCookies comparison.
BodyBody comparison.
ActionComparison of error and result.
MatchThe overall outcome of the step.

Global report

The option gox test -out writes a report of the entire execution. Unlike test.Save(), includes all the selected functions and their totals.

See Execution to know the route resolution and command options.


Integration with Go

The result is a serializable structure that brings together secondary structures for each type of comparison. This allows you to inspect it from the test code or process the JSON generated with other tools.

test.Fail() uses the context installed by the runner to record the failure of the current function. Explain() and Save() they consume the result without rerunning the pipeline.


Best practices

  • Always assess the value match returned by test.Execute().
  • It uses error messages that describe the unfulfilled contract.
  • Executed test.Explain() to obtain useful diagnoses.
  • Save results when you need to keep or compare complete responses.
  • Use -out for global reports and test.Save() for individual executions.

See also

Next step

Continue with Snapshots to compare the body of a response to a reference file.

Snapshots