Skip to content

Commit dd982d8

Browse files
docs: Behat and AI
1 parent 9542d3b commit dd982d8

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

behat_and_ai.rst

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