Skip to content

Commit 29e9e41

Browse files
docs: Behat and AI (#216)
* docs: Behat and AI * Updates after code review
1 parent ce79141 commit 29e9e41

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

behat_and_ai.rst

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Behat and AI
2+
============
3+
4+
AI coding agents can generate and modify code based on behavioural descriptions.
5+
Behat provides a reliable way to define, verify, and preserve behaviour in these workflows.
6+
7+
By expressing behaviour as executable scenarios, Behat ensures that AI-generated code
8+
satisfies a clear and objective contract.
9+
10+
Using Behat as a Behavioural Contract
11+
-------------------------------------
12+
13+
Behat scenarios define observable behaviour in a precise and executable form:
14+
15+
.. code-block:: gherkin
16+
17+
Feature: Refund processing
18+
19+
Scenario: Refunding a paid order
20+
Given there is a paid order
21+
When I refund the order
22+
Then the order should be marked as refunded
23+
24+
Scenario: Prevent duplicate refunds
25+
Given an order has already been refunded
26+
When I refund the order
27+
Then the refund should be rejected
28+
29+
AI agents can implement features and use Behat to verify that the expected behaviour is satisfied.
30+
When scenarios pass, the behavioural contract is fulfilled.
31+
32+
Executable and Verifiable Behaviour
33+
-----------------------------------
34+
35+
Behat scenarios serve as executable specifications. They can be used by AI agents to:
36+
37+
* verify correctness after implementing a feature
38+
* detect behavioural regressions
39+
* ensure behaviour remains consistent during refactoring
40+
41+
Because scenarios are executable, they remain accurate as the system evolves.
42+
43+
Generating Scenarios with AI
44+
----------------------------
45+
46+
AI agents can generate Behat scenarios from behavioural descriptions.
47+
These scenarios can then be reviewed, refined, and executed.
48+
49+
This allows behaviour to be defined before or alongside implementation.
50+
51+
Behat provides a structured and executable representation of behaviour
52+
that can be used directly by AI tooling.
53+
54+
Human Review and Iteration
55+
--------------------------
56+
57+
As with any specification or testing tool, generated scenarios and assertions should be reviewed carefully.
58+
It is critical to ensure that both the human-readable scenarios and the executable step definitions
59+
accurately represent the intended behaviour. They also need to be robust enough to prove that
60+
the actual behaviour matches the expectations, even if the implementation changes.
61+
62+
Once validated, scenarios serve as the authoritative definition of the feature. AI agents can implement
63+
or modify the system until all scenarios pass.
64+
65+
This creates a reliable feedback loop where behaviour is defined, verified, and preserved.
66+
67+
Maintaining Behaviour Over Time
68+
-------------------------------
69+
70+
With well-designed scenarios and step definitions, Behat ensures that behaviour remains stable as code changes.
71+
AI agents can safely modify or refactor code, and Behat will detect any unintended behavioural changes.
72+
73+
As long as scenarios pass, the defined behaviour is preserved.
74+
75+
Behat MCP Server
76+
----------------
77+
78+
Behat provides an `MCP (Model Context Protocol) server`_ that allows AI agents to interact
79+
directly with Behat projects.
80+
81+
The MCP server enables agents to discover scenarios, execute Behat,
82+
and integrate behavioural verification into automated workflows.
83+
84+
.. _`MCP (Model Context Protocol) server`: https://github.com/Behat/mcp-server

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ and many more.
9696
cookbooks
9797
releases
9898
useful_resources
99+
behat_and_ai
99100
community
100101

101102
.. _`Behaviour Driven Development`: https://en.wikipedia.org/wiki/Behavior-driven_development

0 commit comments

Comments
 (0)