dotnet-testing-test-data-builder-pattern

dotnet-testing-test-data-builder-pattern is a skill for Claude Code, Codex from kevintsengtw/dotnet-testing-agent-skills. It costs 187 tokens per session (1,763 once invoked), scanned A, original, MIT.

A guide to the Test Data Builder pattern, a way to create test objects from sensible defaults while changing only the fields relevant to each test. It uses readable builder methods such as setting a name or creating an administrator user.

In plain words
What is it for?
Use it to build complex test data, create common scenarios, override selected properties, combine builders for related objects, and reuse test-data setup.
Why use it?
It keeps test setup short and makes the purpose of each test easier to see, instead of repeating long object definitions.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-test-data-builder-pattern
Any agent
npx skills add kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-test-data-builder-pattern
Clone the repo
git clone --depth 1 https://github.com/kevintsengtw/dotnet-testing-agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for dotnet-testing-test-data-builder-pattern

README.md
[![agentmods](https://agentmods.dev/badge/skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-test-data-builder-pattern.svg)](https://agentmods.dev/skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-test-data-builder-pattern)
Your own site
<a href="https://agentmods.dev/skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-test-data-builder-pattern"><img src="https://agentmods.dev/badge/skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-test-data-builder-pattern.svg" alt="Measured on agentmods" height="20"></a>
Per session 187 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,763 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00187 $0.01763
Opus 5 $0.00093 $0.00881
Sonnet 5 $0.00037 $0.00353
Haiku 4.5 $0.00019 $0.00176

Measured 4d ago against content hash 9353484a5c25, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

dotnet-testing-test-data-builder-pattern scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/dotnet-testing-test-data-builder-pattern/SKILL.md · 126 lines

How it starts

The opening of the file, as written. The whole thing — 126 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Test Data Builder Pattern 測試資料建構器模式

核心概念

什麼是 Test Data Builder Pattern?

Test Data Builder Pattern 是 Object Mother Pattern 的改良版,主要解決以下問題:

  1. 固定測試資料的問題:Object Mother 提供固定的測試物件,難以針對特定測試情境調整
  2. 測試意圖不明確:直接建立物件時,測試的關注點容易被大量屬性設定所掩蓋
  3. 重複程式碼:相似的物件建立邏輯在多個測試中重複出現

為何需要 Builder Pattern?

// ❌ 問題:過多參數設定,測試意圖不明確
var user = new User
{
    Name = "John Doe", Email = "[email protected]", Age = 30,
    Roles = new[] { "User" }, Settings = new UserSettings { Theme = "Dark", Language = "zh-TW" },
    IsActive = true, CreatedAt = DateTime.Now, ModifiedAt = DateTime.Now
};

// ✅ 改善:意圖明確,只設定測試關注的屬性
var user = UserBuilder.AUser().WithName("John Doe").WithValidEmail().Build();

實作指南

基本 Builder 結構

一個標準的 Test Data Builder 應包含:

  1. 預設值:為所有必要屬性提供合理的預設值
  2. 流暢介面:使用 With* 方法鏈來設定屬性
  3. 語意化方法:提供有意義的預設建立者(如 AnAdminUser()ARegularUser()
  4. Build 方法:最終建立並回傳目標物件

涵蓋完整 UserBuilder 實作(預設值、With* 流暢方法、語意化靜態工廠方法、Build 方法)、單一測試情境與配合 Theory 使用的範例。

完整 Builder 實作與測試使用範例請參考 references/builder-implementation.md


最佳實踐

涵蓋五項實踐:提供合理的預設值、使用語意化命名(UserScenarios)、Builder 之間的組合(OrderBuilder 組合 UserBuilder + ProductBuilder)、避免過度複雜化、統一管理測試資料(TestData 靜態類別)。

完整最佳實踐與進階模式請參考 references/best-practices-and-patterns.md


與其他模式的比較

Test Data Builder vs. Object Mother

特性 Test Data Builder Object Mother
彈性 高度彈性,可針對測試調整 固定的測試資料
可讀性 流暢介面,意圖明確 需要查看方法實作
維護性 集中管理,易於修改 變更影響所有測試
使用場景 單元測試、情境測試 簡單的整合測試

Test Data Builder vs. AutoFixture

特性 Test Data Builder AutoFixture
控制度 完全控制物件建立 自動產生,控制度較低
設定複雜度 需手動建立 Builder 幾乎零設定
測試意圖 非常明確 需額外說明
適用時機 需要精確控制的測試 大量資料產生、匿名測試

Read the full file on GitHub · 126 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 126 lines · 187 tokens per session scan A 9353484a5c25

Subscribe to this mod's changes

dotnet-testing-test-data-builder-pattern is a skill published in the GitHub repository kevintsengtw/dotnet-testing-agent-skills (28 stars, last pushed 19d ago), licensed MIT. It adds 187 tokens to every session and 1,763 once invoked, about $0.0009 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

nunit-testing

Use when writing or modifying tests in NUnit's own test projects, or when making a behavioral change to production code that needs test coverage. Covers test structure, attribute choice, helper visibility, platform guards, and which test projects are real.

nunit/nunit · 51 tokens

nunit-threading-and-async

Use when writing or modifying async code in NUnit — async test lifecycle (setup/teardown), TestExecutionContext, AsyncLocal, Task/ValueTask continuations, blocking vs non-blocking waits, or conditional Thread.Abort code. Covers the threading/async conventions the NUnit runtime depends on.

nunit/nunit · 75 tokens

clean-architecture-dotnet

Use when domain logic leaks into API/Infrastructure, project references violate layer boundaries, or you need to decide between CQS (always), CQRS bus (complex domains), and DDD patterns (invariants and events).

SebastienDegodez/copilot-instructions · 50 tokens

creating-dotnet-mcp-servers

Use when building Model Context Protocol (MCP) servers in .NET, configuring tools, transports (SSE/stdio), JSON serialization for AOT, or testing MCP endpoints.

SebastienDegodez/copilot-instructions · 43 tokens

csharp-xunit

Get best practices for XUnit unit testing, including data-driven tests.

Andes-Software-Solutions/Andes.Extensions.AI · 18 tokens

mcaf-dotnet-mstest

Write, run, or repair .NET tests that use MSTest. Use when a repo uses MSTest.Sdk, MSTest, [TestClass], [TestMethod], DataRow, or Microsoft.Testing.Platform-based MSTest execution.

managedcode/MCPGateway · 62 tokens