Dotnet Testing Autofixture Bogus Integration logo

Dotnet Testing Autofixture Bogus Integration

Community
kevintsengtw
dotnet-testing-autofixture-bogus-integration

AutoFixture 與 Bogus 整合完整指南。當需要結合 AutoFixture 與 Bogus 產生兼具匿名性與真實感的測試資料時使用。涵蓋 SpecimenBuilder 整合、混合產生器、測試資料工廠與循環參考處理。 Keywords: autofixture bogus integration, autofixture bogus, bogus integration, Faker, EmailSpecimenBuilder, PhoneSpecimenBuilder, NameSpecimenBuilder, 真實感測試資料, 語意化資料, 混合產生器, HybridTestDataGenerator, OmitOnRecursionBehavior, 循環參考

Overview

Publisherkevintsengtw
Repositorydotnet-testing-agent-skills
Skill namedotnet-testing-autofixture-bogus-integration
Stars
30
Forks
4
Bundled files
5
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by kevintsengtw on GitHub. Read the source before you install it.

Installation

Install the Dotnet Testing Autofixture Bogus Integration AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/kevintsengtw/dotnet-testing-agent-skills/tree/main/skills/dotnet-testing-autofixture-bogus-integration
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/kevintsengtw/dotnet-testing-agent-skills.git /tmp/dotnet-testing-agent-skills
mkdir -p .claude/skills
cp -r /tmp/dotnet-testing-agent-skills/skills/dotnet-testing-autofixture-bogus-integration .claude/skills/dotnet-testing-autofixture-bogus-integration
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Dotnet Testing Autofixture Bogus Integration in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Dotnet Testing Autofixture Bogus Integration on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Dotnet Testing Autofixture Bogus Integration is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

AutoFixture 與 Bogus 整合應用指南

核心概念

為什麼需要整合?

面向AutoFixtureBogus整合方案
資料真實感低(GUID 格式字串)高(真實 Email/Phone)高
物件關聯處理自動手動自動
循環參考處理內建無整合
設定複雜度低中中
適用場景單元測試整合測試/原型兩者皆可

整合效果: user.Email 從 "Email1a2b3c4d" 變為 "john.doe@example.com",其他屬性仍由 AutoFixture 自動填充。

套件安裝

xml
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageReference Include="Bogus" Version="35.6.5" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="AwesomeAssertions" Version="9.4.0" />

整合方式總覽

整合方式適用場景複雜度
屬性層級 SpecimenBuilder特定屬性使用 Bogus低
類型層級 SpecimenBuilder整個類型使用 Bogus中
混合產生器 (HybridGenerator)統一 API 整合中
整合工廠 (IntegratedFactory)完整測試場景建構高
自訂 AutoData 屬性xUnit 整合低

核心整合技術

ISpecimenBuilder 整合

透過 ISpecimenBuilder 介面實現屬性層級與類型層級的整合:

  • 屬性層級:根據屬性名稱判斷(如 Email、Phone、FirstName),使用 Bogus 產生對應的真實感資料
  • 類型層級:為整個類型(如 User、Address)註冊 Bogus Faker 產生器

常用 SpecimenBuilder

SpecimenBuilder產生資料類型Bogus API
EmailSpecimenBuilderEmail 地址f.Internet.Email()
PhoneSpecimenBuilder電話號碼f.Phone.PhoneNumber()
NameSpecimenBuilder人名f.Name.FirstName()
AddressSpecimenBuilder地址f.Address.FullAddress()

擴充方法

  • fixture.WithBogus() — 註冊所有 Bogus SpecimenBuilder
  • fixture.WithOmitOnRecursion() — 處理循環參考
  • fixture.WithSeed(seed) — 設定隨機種子
  • fixture.WithRepeatCount(count) — 設定 CreateMany 預設數量

完整內容請參閱 references/core-integration-techniques.md

循環參考處理

當物件存在循環參考(如 User → Company → Employees(User))時,使用 OmitOnRecursionBehavior 解決:

csharp
var fixture = new Fixture();
fixture.Behaviors.OfType<ThrowingRecursionBehavior>()
    .ToList()
    .ForEach(b => fixture.Behaviors.Remove(b));
fixture.Behaviors.Add(new OmitOnRecursionBehavior());

效果: 避免 StackOverflowException,循環參考的屬性設為 null 或空集合。

自訂 AutoData 屬性

csharp
public class BogusAutoDataAttribute : AutoDataAttribute
{
    public BogusAutoDataAttribute()
        : base(() => new Fixture().WithBogus())
    {
    }
}

// 使用方式
[Theory]
[BogusAutoData]
public void 使用整合資料測試(User user, Address address)
{
    user.Email.Should().Contain("@");
    address.City.Should().NotBeNullOrEmpty();
}

混合產生器與測試資料工廠

HybridTestDataGenerator

統一的測試資料產生 API,實作 ITestDataGenerator 介面:

  • Generate<T>() — 產生單一物件
  • Generate<T>(int count) — 產生指定數量的集合
  • Generate<T>(Action<T> configure) — 產生物件後進行自訂設定

IntegratedTestDataFactory

完整場景建構工廠,支援進階功能:

  • CreateFresh<T>() — 每次產生全新物件
  • CreateMany<T>(count) — 批次建立
  • GetCached<T>() — 快取機制,相同類型只產生一次
  • CreateTestScenario() — 建立包含 Company、Users、Orders 的完整測試場景,自動建立關聯

TestBase 基底類別

統一 Fixture、Generator、Factory 的初始化與 Seed 管理,提供 Create<T>()、CreateMany<T>()、Create<T>(configure) 等便捷方法。

完整程式碼範例請參考 references/hybrid-generator-and-factory.md

Seed 管理與可重現性

重要限制

由於 AutoFixture 和 Bogus 有不同的隨機數管理機制:

  • Seed 確保測試行為穩定性
  • Seed 確保資料格式一致性
  • 無法保證所有屬性值完全相同

建議做法

  • 一般場景:使用 IntegratedTestDataFactory(seed: 12345) 確保穩定性
  • 完全可重現:使用單一工具,如 Faker<User>().UseSeed(12345)
  • 不需重現:不設定 Seed,每次產生不同的隨機資料

常見問題

Q1: 什麼時候該用整合方案,什麼時候用單一工具?

  • 用整合方案:需要真實感資料(Email、Phone)且物件結構複雜的測試場景
  • 用純 AutoFixture:只需要匿名資料填充的單元測試
  • 用純 Bogus:需要完全可重現且資料格式嚴格的整合測試

Q2: SpecimenBuilder 匹配優先順序?

AutoFixture 按照 Customizations 集合的順序匹配,先加入的 Builder 優先。使用 fixture.Customizations.Insert(0, builder) 可確保最高優先。

Q3: 如何為新的實體類型加入 Bogus 支援?

  1. 建立對應的 ISpecimenBuilder 實作
  2. 在 Create() 方法中判斷屬性名稱或類型
  3. 使用 Bogus Faker 產生對應的真實感資料
  4. 在 WithBogus() 擴充方法中註冊

最佳實踐

建議做法

  1. 永遠先處理循環參考 — fixture.WithOmitOnRecursion().WithBogus()
  2. 為常用實體建立專用 SpecimenBuilder
  3. 使用 Seed 確保測試穩定性
  4. 建立測試基底類別統一資料產生邏輯
  5. 適當使用快取提升效能

避免事項

  1. 過度設計,保持簡單實用
  2. 期望整合環境完全可重現
  3. 忽略循環參考處理
  4. 在每個測試中重新建立 Fixture

輸出格式

  • 產生 ISpecimenBuilder 實作類別檔案(如 EmailSpecimenBuilder.cs)
  • 產生 Fixture 擴充方法類別檔案(FixtureBogusExtensions.cs)
  • 產生整合測試資料工廠或混合產生器類別
  • 產生 BogusAutoDataAttribute 供 xUnit Theory 測試使用
  • 搭配 OmitOnRecursionBehavior 處理循環參考

參考資源

範例檔案

原始文章

官方文件

相關技能

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Dotnet Testing Autofixture Bogus Integration AI skill do?

AutoFixture 與 Bogus 整合完整指南。當需要結合 AutoFixture 與 Bogus 產生兼具匿名性與真實感的測試資料時使用。涵蓋 SpecimenBuilder 整合、混合產生器、測試資料工廠與循環參考處理。 Keywords: autofixture bogus integration, autofixture bogus, bogus integration, Faker, EmailSpecimenBuilder, PhoneSpecimenBuilder, NameSpecimenBuilder, 真實感測試資料, 語意化資料, 混合產生器, HybridTestDataGenerator, OmitOnRecursionBehavior, 循環參考

Why use Dotnet Testing Autofixture Bogus Integration on TypingMind?

Because you install it once and use it with any model. Dotnet Testing Autofixture Bogus Integration is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Dotnet Testing Autofixture Bogus Integration in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/kevintsengtw/dotnet-testing-agent-skills/tree/main/skills/dotnet-testing-autofixture-bogus-integration. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Dotnet Testing Autofixture Bogus Integration?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Dotnet Testing Autofixture Bogus Integration?

As many as you like. As long as a model supports skills, you can use Dotnet Testing Autofixture Bogus Integration with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Dotnet Testing Autofixture Bogus Integration AI skill free?

Yes. It is published on GitHub by kevintsengtw under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇