dotnet-testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese.NET 測試基礎技能總覽
.NET Testing Basic Skills Overview
🤖 AI Agent 重要提示
🤖 AI Agent Important Note
當您(AI Agent)被載入此入口 skill 時,請先閱讀以下指引:
When you (AI Agent) are loaded into this entry skill, please read the following guidelines first:
📋 本技能的定位
📋 Positioning of This Skill
本檔案是「導航中心」,用於幫助找到正確的子技能。
This document is a "Navigation Hub" designed to help find the correct sub-skills.
您的任務是
Your Tasks Are
- ✅ 根據使用者需求匹配對應的子技能
- ✅ 使用 tool 載入具體的子技能
Skill - ✅ 讓子技能提供專業的測試指引
- ✅ Match corresponding sub-skills based on user needs
- ✅ Use the tool to load specific sub-skills
Skill - ✅ Let the sub-skills provide professional testing guidance
禁止行為
Prohibited Actions
- ❌ 不要在本入口 skill 中直接提供測試程式碼
- ❌ 不要在沒有載入子技能的情況下開始實作測試
- ❌ 不要跳過子技能直接提供「一般性」測試建議
- ❌ Do not directly provide test code in this entry skill
- ❌ Do not start implementing tests without loading sub-skills
- ❌ Do not skip sub-skills to provide "general" testing recommendations
🎯 快速技能對照表(AI Agent 必讀)
🎯 Quick Skill Reference Table (Must-Read for AI Agents)
使用者提到的關鍵字 → 應載入的子技能
Keywords mentioned by users → Sub-skills to load
最常用技能(必須熟記)
Most Frequently Used Skills (Must Memorize)
| 使用者說... | 載入指令 | 用途說明 |
|---|---|---|
| Validator、驗證器、CreateUserValidator | | FluentValidation 測試 |
| Mock、模擬、IRepository、IService | | 模擬外部依賴 |
| AutoFixture、測試資料生成 | | 自動產生測試資料 |
| 斷言、Should()、BeEquivalentTo | | 流暢斷言(必學) |
| DateTime、時間測試、TimeProvider | | 時間相關測試 |
| File、檔案系統、IFileSystem | | 檔案系統測試 |
| Bogus、假資料、Faker | | 擬真資料生成 |
| Builder Pattern、WithXxx | | Test Data Builder |
| 深層比對、DTO 比對、Excluding | | 複雜物件比對 |
| User says... | Load Command | Purpose |
|---|---|---|
| Validator, validator, CreateUserValidator | | FluentValidation Testing |
| Mock, mocking, IRepository, IService | | Mock external dependencies |
| AutoFixture, test data generation | | Automatically generate test data |
| Assertion, Should(), BeEquivalentTo | | Fluent Assertions (Essential to Learn) |
| DateTime, time testing, TimeProvider | | Time-related testing |
| File, file system, IFileSystem | | File system testing |
| Bogus, fake data, Faker | | Realistic fake data generation |
| Builder Pattern, WithXxx | | Test Data Builder |
| Deep comparison, DTO comparison, Excluding | | Complex object comparison |
基礎入門技能
Basic Entry-Level Skills
| 使用者說... | 載入指令 | 用途說明 |
|---|---|---|
| 從零開始、測試基礎、FIRST 原則 | | 單元測試基礎 |
| 測試命名、如何命名測試 | | 命名規範 |
| 建立測試專案、xUnit 設定 | | 專案建置 |
| User says... | Load Command | Purpose |
|---|---|---|
| Start from scratch, testing fundamentals, FIRST principles | | Unit testing fundamentals |
| Test naming, how to name tests | | Naming conventions |
| Create test project, xUnit setup | | Project setup |
進階技能組合
Advanced Skill Combinations
| 使用者說... | 載入指令 | 用途說明 |
|---|---|---|
| AutoFixture + Bogus | | 自動化+擬真資料 |
| AutoFixture + NSubstitute | | 自動建立 Mock |
| AutoData、Theory 測試 | | 參數化測試 |
| 測試輸出、ITestOutputHelper | | 測試日誌 |
| 覆蓋率、Coverlet | | 程式碼覆蓋率 |
| User says... | Load Command | Purpose |
|---|---|---|
| AutoFixture + Bogus | | Automation + realistic data |
| AutoFixture + NSubstitute | | Automatically create Mocks |
| AutoData, Theory testing | | Parameterized testing |
| Test output, ITestOutputHelper | | Test logging |
| Coverage, Coverlet | | Code coverage analysis |
⚠️ 使用流程範例
⚠️ Usage Flow Examples
✅ 正確流程
✅ Correct Flow
使用者:請幫我建立 CreateUserValidator 的測試
AI:我注意到您需要測試 Validator。根據快速對照表,
我應該載入 dotnet-testing-fluentvalidation-testing skill。
[使用 Skill tool 載入子技能]
AI:現在按照 FluentValidation Testing skill 的指引為您建立測試...User: Please help me create tests for CreateUserValidator
AI: I notice you need to test Validators. According to the quick reference table,
I should load the dotnet-testing-fluentvalidation-testing skill.
[Use Skill tool to load sub-skill]
AI: Now I will create tests for you following the guidelines from the FluentValidation Testing skill...❌ 錯誤流程
❌ Incorrect Flow
使用者:請幫我建立 CreateUserValidator 的測試
AI:好的,我來寫測試...(直接開始寫程式碼,沒有載入子技能)User: Please help me create tests for CreateUserValidator
AI: Sure, I'll write the tests for you... (starts writing code directly without loading sub-skills)📚 完整技能清單
📚 Complete Skill List
To view the complete list of 19 basic skills, detailed decision trees, and learning path recommendations, please continue reading the rest of this document.
For human developers reference: For quick lookup, please check SKILLS_QUICK_INDEX.md
適用情境
Applicable Scenarios
當您遇到以下情況時,我會協助您找到正確的技能:
- 剛開始學習 .NET 測試,不知從何下手
- 想為現有專案建立測試,需要完整指引
- 需要改善測試品質,尋找最佳實踐
- 遇到特定測試場景,不確定該用哪個工具
- 想了解測試資料生成、斷言、模擬等技術
- 希望提升測試可讀性與維護性
- 需要處理時間、檔案系統等特殊測試場景
I will help you find the right skill when you encounter the following situations:
- Just starting to learn .NET testing and don't know where to begin
- Want to create tests for an existing project and need complete guidance
- Need to improve test quality and look for best practices
- Encounter specific testing scenarios and are unsure which tool to use
- Want to learn about test data generation, assertions, mocking, and other techniques
- Hope to improve test readability and maintainability
- Need to handle special testing scenarios such as time, file systems, etc.
快速決策樹
Quick Decision Tree
我應該從哪裡開始?
Where should I start?
情境 1:完全新手,從未寫過測試
Scenario 1: Complete beginner, never written tests before
推薦學習路徑:
- - 理解 FIRST 原則與 3A Pattern
dotnet-testing-unit-test-fundamentals - - 學習命名規範
dotnet-testing-test-naming-conventions - - 建立第一個測試專案
dotnet-testing-xunit-project-setup
為什麼這樣學:
- FIRST 原則是所有測試的基礎,先建立正確的觀念
- 命名規範讓測試易讀易維護
- 實際動手建立專案,將理論轉化為實踐
Recommended Learning Path:
- - Understand FIRST principles and 3A Pattern
dotnet-testing-unit-test-fundamentals - - Learn naming conventions
dotnet-testing-test-naming-conventions - - Create your first test project
dotnet-testing-xunit-project-setup
Why learn this way:
- FIRST principles are the foundation of all testing, establish correct concepts first
- Naming conventions make tests readable and maintainable
- Actually create a project to turn theory into practice
情境 2:會寫基礎測試,但測試資料準備很麻煩
Scenario 2: Can write basic tests but preparing test data is cumbersome
推薦技能(擇一或組合):
選項 A - 自動化優先
→
適合:需要大量測試資料、減少樣板程式碼
dotnet-testing-autofixture-basics選項 B - 擬真資料優先
→
適合:需要真實感的測試資料(姓名、地址、Email 等)
dotnet-testing-bogus-fake-data選項 C - 語意清晰優先
→
適合:需要高可讀性、明確表達測試意圖
dotnet-testing-test-data-builder-pattern選項 D - 兩者兼具
→ +
適合:同時需要自動化和擬真資料
dotnet-testing-autofixture-basicsdotnet-testing-autofixture-bogus-integrationRecommended Skills (choose one or combine):
Option A - Automation First
→
Suitable for: Need large amounts of test data, reduce boilerplate code
dotnet-testing-autofixture-basicsOption B - Realistic Data First
→
Suitable for: Need realistic test data (names, addresses, emails, etc.)
dotnet-testing-bogus-fake-dataOption C - Semantic Clarity First
→
Suitable for: Need high readability, clearly express test intent
dotnet-testing-test-data-builder-patternOption D - Best of Both Worlds
→ +
Suitable for: Need both automation and realistic data
dotnet-testing-autofixture-basicsdotnet-testing-autofixture-bogus-integration情境 3:有外部依賴(資料庫、API、第三方服務)需要模擬
Scenario 3: Have external dependencies (databases, APIs, third-party services) that need mocking
推薦技能組合:
- - NSubstitute Mock 框架基礎
dotnet-testing-nsubstitute-mocking - - (可選)整合 AutoFixture 與 NSubstitute
dotnet-testing-autofixture-nsubstitute-integration
何時需要第二個技能:
- 如果您已經在使用 AutoFixture 產生測試資料
- 想要自動建立 Mock 物件,減少手動設定
Recommended Skill Combination:
- - NSubstitute Mock framework basics
dotnet-testing-nsubstitute-mocking - - (Optional) Integrate AutoFixture with NSubstitute
dotnet-testing-autofixture-nsubstitute-integration
When to use the second skill:
- If you are already using AutoFixture to generate test data
- Want to automatically create Mock objects and reduce manual configuration
情境 4:測試中有特殊場景
Scenario 4: Have special scenarios in testing
時間相關測試
→
處理:DateTime.Now、時區轉換、時間計算
dotnet-testing-datetime-testing-timeprovider檔案系統測試
→
處理:檔案讀寫、目錄操作、路徑處理
dotnet-testing-filesystem-testing-abstractions私有/內部成員測試
→
處理:需要測試 private、internal 成員(但應謹慎使用)
dotnet-testing-private-internal-testingTime-related Testing
→
Handles: DateTime.Now, time zone conversion, time calculations
dotnet-testing-datetime-testing-timeproviderFile System Testing
→
Handles: File reading/writing, directory operations, path handling
dotnet-testing-filesystem-testing-abstractionsPrivate/Internal Member Testing
→
Handles: Need to test private, internal members (but use cautiously)
dotnet-testing-private-internal-testing情境 5:需要更好的斷言方式
Scenario 5: Need better assertion methods
基礎需求 - 流暢斷言
→
所有專案都應該使用,提升測試可讀性
dotnet-testing-awesome-assertions-guide進階需求 - 複雜物件比較
→
處理:深層物件比較、DTO 驗證、Entity 比對
dotnet-testing-complex-object-comparison驗證規則測試
→
處理:測試 FluentValidation 驗證器
dotnet-testing-fluentvalidation-testingBasic Need - Fluent Assertions
→
Should be used in all projects to improve test readability
dotnet-testing-awesome-assertions-guideAdvanced Need - Complex Object Comparison
→
Handles: Deep object comparison, DTO validation, Entity comparison
dotnet-testing-complex-object-comparisonValidation Rule Testing
→
Handles: Testing FluentValidation validators
dotnet-testing-fluentvalidation-testing情境 6:想了解測試覆蓋率
Scenario 6: Want to learn about test coverage
→
學習:使用 Coverlet 分析程式碼覆蓋率、產生報告
dotnet-testing-code-coverage-analysis→
Learn: Use Coverlet to analyze code coverage, generate reports
dotnet-testing-code-coverage-analysis技能分類地圖
Skill Classification Map
將 19 個基礎技能分為 7 大類別(測試基礎、測試資料生成、測試替身、斷言驗證、特殊場景、測試度量、框架整合),每類包含技能對照表、學習路徑與程式碼範例。
📖 詳細內容請參閱 references/skill-classification-map.md
Divide 19 basic skills into 7 major categories (Testing Fundamentals, Test Data Generation, Test Doubles, Assertion Validation, Special Scenarios, Test Metrics, Framework Integration), each category includes a skill reference table, learning path, and code examples.
📖 For detailed content, please refer to references/skill-classification-map.md
常見任務映射表
Common Task Mapping Table
提供 7 個常見測試任務(從零建專案、服務依賴測試、時間邏輯測試等)的技能組合推薦、實施步驟與提示詞範例。
📖 詳細內容請參閱 references/task-mapping-table.md
Provides skill combination recommendations, implementation steps, and prompt examples for 7 common testing tasks (create project from scratch, service dependency testing, time logic testing, etc.).
📖 For detailed content, please refer to references/task-mapping-table.md
學習路徑建議
Learning Path Recommendations
規劃新手路徑(1-2 週)與進階路徑(2-3 週)的每日學習計畫,包含技能、學習重點與實作練習。
📖 詳細內容請參閱 references/learning-paths.md
Plans daily learning schedules for beginner paths (1-2 weeks) and advanced paths (2-3 weeks), including skills, learning focus, and practical exercises.
📖 For detailed content, please refer to references/learning-paths.md
引導對話範例
Guided Conversation Examples
展示 AI 如何與您互動,幫助您選擇正確的技能,包含新手入門、處理依賴、特定問題、改善測試等 4 個常見對話場景。
📖 詳細內容請參閱 references/conversation-examples.md
Demonstrates how AI interacts with you to help you choose the right skill, including 4 common conversation scenarios: beginner introduction, handling dependencies, specific problems, improving tests, etc.
📖 For detailed content, please refer to references/conversation-examples.md
與進階技能的關係
Relationship with Advanced Skills
完成基礎技能後,如果您需要進行整合測試、API 測試、容器化測試或微服務測試,請參考:
進階整合測試 →
dotnet-testing-advanced- ASP.NET Core 整合測試
- 容器化測試(Testcontainers)
- 微服務測試(.NET Aspire)
- 測試框架升級與遷移
After completing the basic skills, if you need to perform integration testing, API testing, containerized testing, or microservices testing, please refer to:
Advanced Integration Testing →
dotnet-testing-advanced- ASP.NET Core integration testing
- Containerized testing (Testcontainers)
- Microservices testing (.NET Aspire)
- Testing framework upgrade and migration
相關資源
Related Resources
原始資料來源
Original Data Sources
-
iThome 鐵人賽系列文章:老派軟體工程師的測試修練 - 30 天挑戰 🏆 2025 iThome 鐵人賽 Software Development 組冠軍
-
完整範例程式碼:30Days_in_Testing_Samples 包含所有範例專案的可執行程式碼
-
iThome Ironman Series Articles: Testing Practice for Old-School Software Engineers - 30-Day Challenge 🏆 2025 iThome Ironman Competition Software Development Group Champion
-
Complete Sample Code: 30Days_in_Testing_Samples Contains executable code for all sample projects
學習文檔
Learning Documents
本技能集基於以下完整教材提煉而成:
-
Agent Skills:從架構設計到實戰應用 (docs/Agent_Skills_Mastery.pdf) 完整涵蓋 Agent Skills 從理論到實踐
-
Claude Code Skills: 讓 AI 變身專業工匠 (docs/Agent_Skills_Architecture.pdf) 深入解析 Agent Skills 的架構設計
-
.NET Testing:寫得更好、跑得更快 (docs/NET_Testing_Write_Better_Run_Faster.pdf) 測試執行優化與除錯技巧
This skill set is refined based on the following complete teaching materials:
-
Agent Skills: From Architecture Design to Practical Application (docs/Agent_Skills_Mastery.pdf) Fully covers Agent Skills from theory to practice
-
Claude Code Skills: Turn AI into a Professional Artisan (docs/Agent_Skills_Architecture.pdf) In-depth analysis of Agent Skills architecture design
-
.NET Testing: Write Better, Run Faster (docs/NET_Testing_Write_Better_Run_Faster.pdf) Test execution optimization and debugging techniques
下一步
Next Steps
選擇符合您需求的技能開始學習,或告訴我您的具體情況,我會推薦最適合的學習路徑!
快速開始:
- 新手 → 從 開始
dotnet-testing-unit-test-fundamentals - 有經驗 → 告訴我您遇到的具體問題
- 不確定 → 告訴我您的專案情況,我會幫您分析
Choose the skill that meets your needs to start learning, or tell me your specific situation and I will recommend the most suitable learning path!
Quick Start:
- Beginners → Start with
dotnet-testing-unit-test-fundamentals - Experienced → Tell me the specific problem you encountered
- Unsure → Tell me about your project and I will help you analyze it