Skip to content

Commit 1dc56f2

Browse files
committed
Add docs for TestEntityBuilder
1 parent 8065bc7 commit 1dc56f2

3 files changed

Lines changed: 896 additions & 0 deletions

File tree

docs/testing/ci-testing/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ <h1 id="breadcrumb">
8686
<li >
8787
<a href="/docs/testing/#scriptRunner">DDL/SQL Script runner</a>
8888
</li>
89+
<li >
90+
<a href="/docs/testing/test-entity-builder">Test Entity Builder</a>
91+
</li>
8992
<li class="active">
9093
<a class="active" href="/docs/testing/ci-testing">CI - Jenkins etc</a>
9194
</li>

docs/testing/index.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ <h1 id="breadcrumb">
8686
<li >
8787
<a href="/docs/testing/#scriptRunner">DDL/SQL Script runner</a>
8888
</li>
89+
<li >
90+
<a href="/docs/testing/test-entity-builder">Test Entity Builder</a>
91+
</li>
8992
<li >
9093
<a href="/docs/testing/ci-testing">CI - Jenkins etc</a>
9194
</li>
@@ -264,6 +267,51 @@ <h3>3. Add ~/.ebean/ignore-docker-shutdown</h3>
264267
<li>Current user and tenant provider if not already specified (to ease testing with @Who properties etc)</li>
265268
</ul>
266269

270+
<h2 id="testEntityBuilder">Test Entity Builder</h2>
271+
272+
<p>
273+
The <code>TestEntityBuilder</code> class is a utility for rapidly creating test entity instances
274+
with auto-populated random values. This is particularly useful for integration tests where you need
275+
representative data without manually setting each field.
276+
</p>
277+
278+
<p>
279+
Key features:
280+
</p>
281+
282+
<ul>
283+
<li>Auto-generates appropriate random values for all supported types</li>
284+
<li>Respects column length and decimal precision constraints</li>
285+
<li>Handles entity relationships with cascade persist</li>
286+
<li>Cycle detection prevents infinite recursion</li>
287+
<li>Customizable via subclassing <code>RandomValueGenerator</code></li>
288+
</ul>
289+
290+
<p>
291+
Example usage:
292+
</p>
293+
294+
<div class="syntax java"><div class="highlight"><pre><span></span><span class="n">TestEntityBuilder</span> <span class="n">builder</span> <span class="o">=</span> <span class="n">TestEntityBuilder</span><span class="o">.</span><span class="na">builder</span><span class="o">(</span><span class="n">DB</span><span class="o">.</span><span class="na">getDefault</span><span class="o">()).</span><span class="na">build</span><span class="o">();</span>
295+
296+
<span class="c1">// Build in-memory (not persisted)</span>
297+
<span class="n">Product</span> <span class="n">product</span> <span class="o">=</span> <span class="n">builder</span><span class="o">.</span><span class="na">build</span><span class="o">(</span><span class="n">Product</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
298+
299+
<span class="c1">// Build and save to database</span>
300+
<span class="n">Product</span> <span class="n">saved</span> <span class="o">=</span> <span class="n">builder</span><span class="o">.</span><span class="na">save</span><span class="o">(</span><span class="n">Product</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
301+
</pre></div>
302+
</div>
303+
304+
<p>
305+
<a href="/docs/testing/test-entity-builder">See the full Test Entity Builder guide</a> for detailed setup,
306+
usage, examples, and best practices.
307+
</p>
308+
309+
<p>
310+
<strong>For AI Agents:</strong> Step-by-step guides for using TestEntityBuilder and other tasks are available at
311+
<a href="https://github.com/ebean-orm/ebean/tree/master/docs/guides/README.md">docs/guides/README.md</a>
312+
in the GitHub repository.
313+
</p>
314+
267315
<h2 id="test-platform">ebean.test.platform - application-test.yaml</h2>
268316
<p>
269317
We use <code>ebean.test.platform</code> to specify the database platform we want to use when running tests.

0 commit comments

Comments
 (0)