Skip to content

Conversation

@carlos-granados
Copy link
Contributor

@carlos-granados carlos-granados commented Oct 19, 2025

Lately JSON has become the lingua franca of tools, which use this format to exchange information everywhere. This PR introduces a JSON formatter which is able to save Behat test results as a JSON file. One possible application for this format is to be able to create an MCP server for Behat, using the generated JSON to return information to the client

This formatter is heavily inspired in the existing JUnit formatter and the exported output is similar but, since it is not constrained by the existing JUnit specification, it follows more closely the structure of our project. The generated JSON basically will contain a list of Suite nodes, which will contain Feature nodes, which will contain Scenario nodes. Each node will have properties indicating some info like the status, the number of tests for each status, file and line and execution time. Also, the JUnit formatter produced one file per suite, this formatter produces just a single JSON file for all suites so the output_path needs to be a file name, not a folder name

The PR also defines a JSON schema which can be used by the tools that will use this information

@@ -0,0 +1,125 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/test-report.schema.json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this use behat.org instead of example.com ?

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is brilliant, thanks for all the work on this @carlos-granados

A few small comments / questions that I spotted when going through it, but overall it's in great shape.

@carlos-granados
Copy link
Contributor Author

@stof I updated the schema file according to your comments, thanks for pointing those things out! I will now look into the comments from @acoulton

@carlos-granados
Copy link
Contributor Author

@acoulton the time fields have been changed to be proper floats rounded to 3 decimals and I updated the field description in the json schema, let me know if it looks ok now

@carlos-granados
Copy link
Contributor Author

@acoulton updated, thanks for all your suggestions. I also changed a few properties which I saw had been defined as unnecessarily nullable. Please let me know if it looks ok now

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great @carlos-granados just one small naming thing in the updated schema and (the discussion about paths. now resolved)

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant, great work @carlos-granados thank you :)

@carlos-granados carlos-granados merged commit b027e95 into Behat:master Oct 23, 2025
19 checks passed
@carlos-granados carlos-granados deleted the json-formatter branch October 23, 2025 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants