{"id":"e9f29890-ced7-46c8-b36e-58d0b7330500","shortId":"bPTC7h","kind":"skill","title":"dotnet-testing-advanced-tunit-advanced","tagline":"TUnit 進階應用完整指南。當需要使用 TUnit 進行資料驅動測試、依賴注入或整合測試時使用。涵蓋 MethodDataSource、ClassDataSource、Matrix Tests、Properties 過濾。包含 Retry/Timeout 控制、WebApplicationFactory 整合、Testcontainers 多服務編排。\nMake sure to use this skill whenever the user mentions TUnit advanced, MethodDataSource, ClassDataSou","description":"# TUnit 進階應用：資料驅動測試、依賴注入與整合測試實戰\n\n## 資料驅動測試進階技巧\n\nTUnit 提供 MethodDataSource、ClassDataSource、Matrix Tests 三種進階資料來源。MethodDataSource 最靈活，支援動態產生與外部檔案載入；ClassDataSource 適合跨測試類別共享資料與 AutoFixture 整合；Matrix Tests 自動產生所有參數組合（注意控制數量避免爆炸性增長）。\n\n> 完整範例與比較表請參閱 [references/data-driven-testing.md](references/data-driven-testing.md)\n\n---\n\n## Properties 屬性標記與測試過濾\n\n### 基本 Properties 使用\n\n```csharp\n[Test]\n[Property(\"Category\", \"Database\")]\n[Property(\"Priority\", \"High\")]\npublic async Task DatabaseTest_高優先級_應能透過屬性過濾()\n{\n    await Assert.That(true).IsTrue();\n}\n\n[Test]\n[Property(\"Category\", \"Unit\")]\n[Property(\"Priority\", \"Medium\")]\npublic async Task UnitTest_中等優先級_基本驗證()\n{\n    await Assert.That(1 + 1).IsEqualTo(2);\n}\n\n[Test]\n[Property(\"Category\", \"Integration\")]\n[Property(\"Priority\", \"Low\")]\n[Property(\"Environment\", \"Development\")]\npublic async Task IntegrationTest_低優先級_僅開發環境執行()\n{\n    await Assert.That(\"Hello World\").Contains(\"World\");\n}\n```\n\n### 建立一致的屬性命名規範\n\n```csharp\npublic static class TestProperties\n{\n    // 測試類別\n    public const string CATEGORY_UNIT = \"Unit\";\n    public const string CATEGORY_INTEGRATION = \"Integration\";\n    public const string CATEGORY_E2E = \"E2E\";\n\n    // 優先級\n    public const string PRIORITY_CRITICAL = \"Critical\";\n    public const string PRIORITY_HIGH = \"High\";\n    public const string PRIORITY_MEDIUM = \"Medium\";\n    public const string PRIORITY_LOW = \"Low\";\n\n    // 環境\n    public const string ENV_DEVELOPMENT = \"Development\";\n    public const string ENV_STAGING = \"Staging\";\n    public const string ENV_PRODUCTION = \"Production\";\n}\n\n[Test]\n[Property(\"Category\", TestProperties.CATEGORY_UNIT)]\n[Property(\"Priority\", TestProperties.PRIORITY_HIGH)]\npublic async Task ExampleTest_使用常數_確保一致性()\n{\n    await Assert.That(1 + 1).IsEqualTo(2);\n}\n```\n\n### TUnit 測試過濾執行\n\nTUnit 使用 `dotnet run` 而不是 `dotnet test`：\n\n```bash\n# 只執行單元測試\ndotnet run --treenode-filter \"/*/*/*/*[Category=Unit]\"\n\n# 只執行高優先級測試\ndotnet run --treenode-filter \"/*/*/*/*[Priority=High]\"\n\n# 組合條件：執行高優先級的單元測試\ndotnet run --treenode-filter \"/*/*/*/*[(Category=Unit)&(Priority=High)]\"\n\n# 或條件：執行單元測試或冒煙測試\ndotnet run --treenode-filter \"/*/*/*/*[(Category=Unit)|(Suite=Smoke)]\"\n\n# 執行特定功能的測試\ndotnet run --treenode-filter \"/*/*/*/*[Feature=OrderProcessing]\"\n```\n\n**過濾語法注意事項：**\n- 路徑模式 `/*/*/*/*` 代表 Assembly/Namespace/Class/Method 層級\n- 屬性名稱大小寫敏感\n- 組合條件必須用括號正確包圍\n\n---\n\n## 測試生命週期管理\n\nTUnit 提供完整的生命週期鉤子：`[Before(Class)]` → 建構式 → `[Before(Test)]` → 測試方法 → `[After(Test)]` → Dispose → `[After(Class)]`。另有 Assembly/TestSession 層級與 `[BeforeEvery]`/`[AfterEvery]` 全域鉤子。建構式永遠最先執行，BeforeClass/AfterClass 各只執行一次。\n\n> 完整屬性家族與範例請參閱 [references/lifecycle-management.md](references/lifecycle-management.md)\n\n---\n\n## 依賴注入模式\n\n### TUnit 依賴注入核心概念\n\nTUnit 的依賴注入建構在 Data Source Generators 基礎上：\n\n```csharp\npublic class MicrosoftDependencyInjectionDataSourceAttribute : DependencyInjectionDataSourceAttribute<IServiceScope>\n{\n    private static readonly IServiceProvider ServiceProvider = CreateSharedServiceProvider();\n\n    public override IServiceScope CreateScope(DataGeneratorMetadata dataGeneratorMetadata)\n    {\n        return ServiceProvider.CreateScope();\n    }\n\n    public override object? Create(IServiceScope scope, Type type)\n    {\n        return scope.ServiceProvider.GetService(type);\n    }\n\n    private static IServiceProvider CreateSharedServiceProvider()\n    {\n        return new ServiceCollection()\n            .AddSingleton<IOrderRepository, MockOrderRepository>()\n            .AddSingleton<IDiscountCalculator, MockDiscountCalculator>()\n            .AddSingleton<IShippingCalculator, MockShippingCalculator>()\n            .AddSingleton<ILogger<OrderService>, MockLogger<OrderService>>()\n            .AddTransient<OrderService>()\n            .BuildServiceProvider();\n    }\n}\n```\n\n### 使用 TUnit 依賴注入\n\n```csharp\n[MicrosoftDependencyInjectionDataSource]\npublic class DependencyInjectionTests(OrderService orderService)\n{\n    [Test]\n    public async Task CreateOrder_使用TUnit依賴注入_應正確運作()\n    {\n        // Arrange - 依賴已經透過 TUnit DI 自動注入\n        var items = new List<OrderItem>\n        {\n            new() { ProductId = \"PROD001\", ProductName = \"測試商品\", UnitPrice = 100m, Quantity = 2 }\n        };\n\n        // Act\n        var order = await orderService.CreateOrderAsync(\"CUST001\", CustomerLevel.VIP會員, items);\n\n        // Assert\n        await Assert.That(order).IsNotNull();\n        await Assert.That(order.CustomerId).IsEqualTo(\"CUST001\");\n        await Assert.That(order.CustomerLevel).IsEqualTo(CustomerLevel.VIP會員);\n    }\n\n    [Test]\n    public async Task TUnitDependencyInjection_驗證自動注入_服務應為正確類型()\n    {\n        await Assert.That(orderService).IsNotNull();\n        await Assert.That(orderService.GetType().Name).IsEqualTo(\"OrderService\");\n    }\n}\n```\n\n### TUnit DI vs 手動依賴建立比較\n\n| 特性           | TUnit DI                 | 手動依賴建立               |\n| :------------- | :----------------------- | :------------------------- |\n| **設定複雜度** | 一次設定，重複使用       | 每個測試都需要手動建立     |\n| **可維護性**   | 依賴變更只需修改一個地方 | 需要修改所有使用的測試     |\n| **一致性**     | 與產品程式碼的 DI 一致   | 可能與實際應用程式不一致   |\n| **測試可讀性** | 專注於測試邏輯           | 被依賴建立程式碼干擾       |\n| **範圍管理**   | 自動管理服務範圍         | 需要手動管理物件生命週期   |\n| **錯誤風險**   | 框架保證依賴正確注入     | 可能遺漏或錯誤建立某些依賴 |\n\n---\n\n## 執行控制與測試品質\n\n- **`[Retry(n)]`**：僅用於外部依賴造成的不穩定測試（網路、檔案鎖定），不用於邏輯錯誤\n- **`[Timeout(ms)]`**：為效能敏感測試設定合理上限，搭配 `Stopwatch` 驗證 SLA\n- **`[DisplayName]`**：支援 `{0}` 參數插值，讓測試報告更貼近業務語言\n\n> 完整範例（Retry/Timeout/DisplayName）請參閱 [references/execution-control.md](references/execution-control.md)\n\n---\n\n## ASP.NET Core 整合測試\n\n在 TUnit 中使用 `WebApplicationFactory<Program>` 進行 ASP.NET Core 整合測試，透過實作 `IDisposable` 管理生命週期。涵蓋 API 回應驗證、Content-Type 標頭檢查，以及效能基準與並行負載測試。\n\n> 完整 WebApplicationFactory 整合與負載測試範例請參閱 [references/aspnet-integration.md](references/aspnet-integration.md)\n\n---\n\n## TUnit + Testcontainers 基礎設施編排\n\n使用 `[Before(Assembly)]` / `[After(Assembly)]` 在 Assembly 層級管理 PostgreSQL、Redis、Kafka 等多容器編排，搭配 `NetworkBuilder` 建立共用網路。容器僅啟動一次，大幅減少啟動時間與資源消耗，同時保持測試間的資料隔離。\n\n> 完整多容器編排與全域共享範例請參閱 [references/tunit-testcontainers.md](references/tunit-testcontainers.md)\n\n---\n\n## TUnit Engine Modes\n\n### Source Generation Mode（預設模式）\n\n```text\n████████╗██╗   ██╗███╗   ██╗██╗████████╗\n╚══██╔══╝██║   ██║████╗  ██║██║╚══██╔══╝\n   ██║   ██║   ██║██╔██╗ ██║██║   ██║\n   ██║   ██║   ██║██║╚██╗██║██║   ██║\n   ██║   ╚██████╔╝██║ ╚████║██║   ██║\n   ╚═╝    ╚═════╝ ╚═╝  ╚═══╝╚═╝   ╚═╝\n\n   Engine Mode: SourceGenerated\n```\n\n**特色與優勢：**\n\n- **編譯時期產生**：所有測試發現邏輯在編譯時產生，不需要執行時反射\n- **效能優異**：比反射模式快數倍\n- **型別安全**：編譯時期驗證測試配置和資料來源\n- **AOT 相容**：完全支援 Native AOT 編譯\n\n### Reflection Mode（反射模式）\n\n```bash\n# 啟用反射模式\ndotnet run -- --reflection\n\n# 或設定環境變數\n$env:TUNIT_EXECUTION_MODE = \"reflection\"\ndotnet run\n```\n\n**適用場景：**\n\n- 動態測試發現\n- F# 和 VB.NET 專案（自動使用）\n- 某些依賴反射的測試模式\n\n### Native AOT 支援\n\n```xml\n<PropertyGroup>\n    <PublishAot>true</PublishAot>\n</PropertyGroup>\n```\n\n```bash\ndotnet publish -c Release\n```\n\n---\n\n## 常見問題與疑難排解\n\n### 測試統計顯示異常問題\n\n**問題現象：** `測試摘要: 總計: 0, 失敗: 0, 成功: 0`\n\n**解決步驟：**\n\n1. **確保專案檔設定正確：**\n\n```xml\n<PropertyGroup>\n    <IsTestProject>true</IsTestProject>\n</PropertyGroup>\n```\n\n2. **確保 GlobalUsings.cs 正確：**\n\n```csharp\nglobal using System;\nglobal using System.Collections.Generic;\nglobal using System.Linq;\nglobal using System.Threading.Tasks;\nglobal using TUnit.Core;\nglobal using TUnit.Assertions;\nglobal using TUnit.Assertions.Extensions;\n```\n\n3. **整合測試的特殊設定：**\n\n```csharp\n// 在 WebApi 專案的 Program.cs 最後加上\npublic partial class Program { }  // 讓整合測試可以存取\n```\n\n4. **清理和重建：**\n\n```bash\ndotnet clean; dotnet build\ndotnet test --verbosity normal\n```\n\n### Source Generator 相關問題\n\n**問題：測試類別無法被發現**\n\n- **解決**：確保專案完全重建 (`dotnet clean; dotnet build`)\n\n**問題：編譯時出現奇怪錯誤**\n\n- **解決**：檢查是否有其他 Source Generator 套件，考慮更新到相容版本\n\n### 診斷選項\n\n```ini\n# .editorconfig\ntunit.enable_verbose_diagnostics = true\n```\n\n```xml\n<PropertyGroup>\n    <TUnitEnableVerboseDiagnostics>true</TUnitEnableVerboseDiagnostics>\n</PropertyGroup>\n```\n\n---\n\n## 實務建議\n\n### 資料驅動測試的選擇策略\n\n- **MethodDataSource**：適合動態資料、複雜物件、外部檔案載入\n- **ClassDataSource**：適合共享資料、AutoFixture 整合、跨測試類別重用\n- **Matrix Tests**：適合組合測試，但要注意參數數量避免爆炸性增長\n\n### 執行控制最佳實踐\n\n- **Retry**：只用於真正不穩定的外部依賴測試\n- **Timeout**：為效能敏感的測試設定合理限制\n- **DisplayName**：讓測試報告更符合業務語言\n\n### 整合測試策略\n\n- 使用 WebApplicationFactory 進行完整的 Web API 測試\n- 運用 TUnit + Testcontainers 建立複雜多服務測試環境\n- 透過屬性注入系統管理複雜的依賴關係\n- 只測試實際存在的功能，避免測試不存在的端點\n\n---\n\n## 範本檔案\n\n| 檔案名稱                                                                 | 說明                                   |\n| ------------------------------------------------------------------------ | -------------------------------------- |\n| [data-source-examples.cs](templates/data-source-examples.cs)             | MethodDataSource、ClassDataSource 範例 |\n| [matrix-tests-examples.cs](templates/matrix-tests-examples.cs)           | Matrix Tests 組合測試範例              |\n| [lifecycle-di-examples.cs](templates/lifecycle-di-examples.cs)           | 生命週期管理與依賴注入範例             |\n| [execution-control-examples.cs](templates/execution-control-examples.cs) | Retry、Timeout、DisplayName 範例       |\n| [aspnet-integration-tests.cs](templates/aspnet-integration-tests.cs)     | ASP.NET Core 整合測試範例              |\n| [testcontainers-examples.cs](templates/testcontainers-examples.cs)       | Testcontainers 基礎設施編排範例        |\n\n---\n\n## 輸出格式\n\n- 產生使用 MethodDataSource/ClassDataSource/Matrix Tests 的資料驅動測試類別（.cs 檔案）\n- 包含 MicrosoftDependencyInjectionDataSource 依賴注入設定\n- 包含 Retry/Timeout/DisplayName 執行控制範例\n- 產生 WebApplicationFactory 整合測試與 Testcontainers 多容器編排程式碼\n\n## 參考資源\n\n### 原始文章\n\n本技能內容提煉自「老派軟體工程師的測試修練 - 30 天挑戰」系列文章：\n\n- **Day 29 - TUnit 進階應用：資料驅動測試與依賴注入深度實戰**\n  - 鐵人賽文章：https://ithelp.ithome.com.tw/articles/10377970\n  - 範例程式碼：https://github.com/kevintsengtw/30Days_in_Testing_Samples/tree/main/day29\n\n- **Day 30 - TUnit 進階應用 - 執行控制與測試品質和 ASP.NET Core 整合測試實戰**\n  - 鐵人賽文章：https://ithelp.ithome.com.tw/articles/10378176\n  - 範例程式碼：https://github.com/kevintsengtw/30Days_in_Testing_Samples/tree/main/day30\n\n### TUnit 官方資源\n\n- [TUnit 官方網站](https://tunit.dev/)\n- [TUnit GitHub Repository](https://github.com/thomhurst/TUnit)\n\n### 進階功能文件\n\n- [TUnit Method Data Source 文件](https://tunit.dev/docs/test-authoring/method-data-source)\n- [TUnit Class Data Source 文件](https://tunit.dev/docs/test-authoring/class-data-source)\n- [TUnit Matrix Tests 文件](https://tunit.dev/docs/test-authoring/matrix-tests)\n- [TUnit Properties 文件](https://tunit.dev/docs/test-lifecycle/properties)\n- [TUnit Dependency Injection 文件](https://tunit.dev/docs/test-lifecycle/dependency-injection)\n- [TUnit Retrying 文件](https://tunit.dev/docs/execution/retrying)\n- [TUnit Timeouts 文件](https://tunit.dev/docs/execution/timeouts)\n- [TUnit Engine Modes 文件](https://tunit.dev/docs/execution/engine-modes)\n- [TUnit ASP.NET Core 文件](https://tunit.dev/docs/examples/aspnet)\n- [TUnit Complex Test Infrastructure](https://tunit.dev/docs/examples/complex-test-infrastructure-orchestration)\n\n### Testcontainers 相關資源\n\n- [Testcontainers.NET 官方網站](https://dotnet.testcontainers.org/)\n- [Testcontainers.NET GitHub](https://github.com/testcontainers/testcontainers-dotnet)\n\n### 相關技能\n\n- `dotnet-testing-advanced-tunit-fundamentals` - TUnit 基礎（前置技能）\n- `dotnet-testing-advanced-aspnet-integration-testing` - ASP.NET Core 整合測試\n- `dotnet-testing-advanced-testcontainers-database` - Testcontainers 資料庫測試","tags":["dotnet","testing","advanced","tunit","agent","skills","kevintsengtw","agent-skills","ai-assisted-development","copilot-skills","csharp","dotnet-testing"],"capabilities":["skill","source-kevintsengtw","skill-dotnet-testing-advanced-tunit-advanced","topic-agent-skills","topic-ai-assisted-development","topic-copilot-skills","topic-csharp","topic-dotnet","topic-dotnet-testing","topic-github-copilot","topic-integration-testing","topic-testing","topic-unit-testing","topic-xunit"],"categories":["dotnet-testing-agent-skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-advanced-tunit-advanced","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add kevintsengtw/dotnet-testing-agent-skills","source_repo":"https://github.com/kevintsengtw/dotnet-testing-agent-skills","install_from":"skills.sh"}},"qualityScore":"0.461","qualityRationale":"deterministic score 0.46 from registry signals: · indexed on github topic:agent-skills · 23 github stars · SKILL.md body (11,175 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-04-24T13:02:25.472Z","embedding":null,"createdAt":"2026-04-18T23:04:18.603Z","updatedAt":"2026-04-24T13:02:25.472Z","lastSeenAt":"2026-04-24T13:02:25.472Z","tsv":"'/)':830,913 '/articles/10377970':803 '/articles/10378176':819 '/docs/examples/aspnet)':899 '/docs/examples/complex-test-infrastructure-orchestration)':906 '/docs/execution/engine-modes)':892 '/docs/execution/retrying)':879 '/docs/execution/timeouts)':885 '/docs/test-authoring/class-data-source)':853 '/docs/test-authoring/matrix-tests)':860 '/docs/test-authoring/method-data-source)':845 '/docs/test-lifecycle/dependency-injection)':873 '/docs/test-lifecycle/properties)':866 '/kevintsengtw/30days_in_testing_samples/tree/main/day29':807 '/kevintsengtw/30days_in_testing_samples/tree/main/day30':823 '/testcontainers/testcontainers-dotnet)':918 '/thomhurst/tunit)':836 '0':492,615,617,619 '1':105,106,217,218,621 '100m':402 '2':108,220,404,625 '29':796 '3':651 '30':792,809 '4':664 'act':405 'addsingleton':356,359,362,365 'addtransi':368 'advanc':4,6,38,923,932,942 'aftereveri':302 'aot':570,574,601 'api':515,730 'arrang':387 'asp.net':500,508,763,813,894,936 'aspnet':933 'aspnet-integration-tests.cs':761 'assembl':532,534,536 'assembly/namespace/class/method':280 'assembly/testsession':299 'assert':414 'assert.that':87,104,126,216,416,420,425,438,442 'async':81,98,120,210,382,432 'autofixtur':58,711 'await':86,103,125,215,408,415,419,424,437,441 'bash':230,579,605,666 'beforeclass/afterclass':305 'beforeeveri':301 'build':670,685 'buildserviceprovid':369 'c':608 'categori':75,92,111,141,147,153,202,237,254,265 'class':135,288,297,321,376,661,847 'classdatasou':40 'classdatasourc':15,49,56,709,745 'clean':668,683 'complex':901 'const':139,145,151,158,164,170,176,183,189,195 'contain':129 'content':518 'content-typ':517 'core':501,509,764,814,895,937 'creat':341 'createord':384 'createscop':333 'createsharedserviceprovid':329,352 'critic':161,162 'cs':775 'csharp':72,132,319,373,629,653 'cust001':410,423 'customerlevel.vip':411,428 'data':315,840,848 'data-source-examples.cs':742 'databas':76,944 'databasetest':83 'datageneratormetadata':334,335 'day':795,808 'depend':868 'dependencyinjectiondatasourceattribut':323 'dependencyinjectiontest':377 'develop':118,186,187 'di':390,448,453,464 'diagnost':699 'displaynam':490,723,759 'dispos':295 'dotnet':2,225,228,232,240,249,260,270,581,590,606,667,669,671,682,684,921,930,940 'dotnet-testing-advanced-aspnet-integration-test':929 'dotnet-testing-advanced-testcontainers-databas':939 'dotnet-testing-advanced-tunit-advanc':1 'dotnet-testing-advanced-tunit-fundament':920 'dotnet.testcontainers.org':912 'dotnet.testcontainers.org/)':911 'e2e':154,155 'editorconfig':696 'engin':552,559,887 'env':185,191,197,585 'environ':117 'exampletest':212 'execut':587 'execution-control-examples.cs':755 'f':594 'featur':275 'filter':236,244,253,264,274 'fundament':925 'generat':317,555,676,691 'github':832,915 'github.com':806,822,835,917 'github.com/kevintsengtw/30days_in_testing_samples/tree/main/day29':805 'github.com/kevintsengtw/30days_in_testing_samples/tree/main/day30':821 'github.com/testcontainers/testcontainers-dotnet)':916 'github.com/thomhurst/tunit)':834 'global':630,633,636,639,642,645,648 'globalusings.cs':627 'hello':127 'high':79,167,168,208,246,257 'idiscountcalcul':360 'idispos':512 'ilogg':366 'infrastructur':903 'ini':695 'inject':869 'integr':112,148,149,934 'integrationtest':122 'iorderrepositori':357 'isequalto':107,219,422,427,445 'iserviceprovid':327,351 'iservicescop':332,342 'ishippingcalcul':363 'isnotnul':418,440 'istru':89 'item':393,413 'ithelp.ithome.com.tw':802,818 'ithelp.ithome.com.tw/articles/10377970':801 'ithelp.ithome.com.tw/articles/10378176':817 'kafka':540 'lifecycle-di-examples.cs':752 'list':395 'low':115,179,180 'make':27 'matrix':16,50,60,714,749,855 'matrix-tests-examples.cs':747 'medium':96,173,174 'mention':36 'method':839 'methoddatasourc':14,39,48,53,705,744 'methoddatasource/classdatasource/matrix':772 'microsoftdependencyinjectiondatasourc':374,778 'microsoftdependencyinjectiondatasourceattribut':322 'mockdiscountcalcul':361 'mocklogg':367 'mockorderrepositori':358 'mockshippingcalcul':364 'mode':553,556,560,577,588,888 'ms':484 'n':478 'name':444 'nativ':573,600 'networkbuild':543 'new':354,394,396 'normal':674 'object':340 'order':407,417 'order.customerid':421 'order.customerlevel':426 'orderprocess':276 'orderservic':378,379,439,446 'orderservice.createorderasync':409 'orderservice.gettype':443 'overrid':331,339 'partial':660 'postgresql':538 'prioriti':78,95,114,160,166,172,178,206,245,256 'privat':324,349 'prod001':398 'product':198,199 'productid':397 'productnam':399 'program':662 'program.cs':657 'properti':18,67,70,74,77,91,94,110,113,116,201,205,862 'public':80,97,119,133,138,144,150,157,163,169,175,182,188,194,209,320,330,338,375,381,431,659 'publish':607 'quantiti':403 'readon':326 'redi':539 'references/aspnet-integration.md':525,526 'references/data-driven-testing.md':65,66 'references/execution-control.md':498,499 'references/lifecycle-management.md':308,309 'references/tunit-testcontainers.md':549,550 'reflect':576,583,589 'releas':609 'repositori':833 'retri':477,719,757,875 'retry/timeout':21 'retry/timeout/displayname':496,781 'return':336,346,353 'run':226,233,241,250,261,271,582,591 'scope':343 'scope.serviceprovider.getservice':347 'servicecollect':355 'serviceprovid':328 'serviceprovider.createscope':337 'skill':32 'skill-dotnet-testing-advanced-tunit-advanced' 'sla':489 'smoke':268 'sourc':316,554,675,690,841,849 'source-kevintsengtw' 'sourcegener':561 'stage':192,193 'static':134,325,350 'stopwatch':487 'string':140,146,152,159,165,171,177,184,190,196 'suit':267 'sure':28 'system':632 'system.collections.generic':635 'system.linq':638 'system.threading.tasks':641 'task':82,99,121,211,383,433 'templates/aspnet-integration-tests.cs':762 'templates/data-source-examples.cs':743 'templates/execution-control-examples.cs':756 'templates/lifecycle-di-examples.cs':753 'templates/matrix-tests-examples.cs':748 'templates/testcontainers-examples.cs':767 'test':3,17,51,61,73,90,109,200,229,291,294,380,430,672,715,750,773,856,902,922,931,935,941 'testcontain':25,528,734,768,786,907,943,945 'testcontainers-examples.cs':766 'testcontainers.net':909,914 'testproperti':136 'testproperties.category':203 'testproperties.priority':207 'text':558 'timeout':483,721,758,881 'topic-agent-skills' 'topic-ai-assisted-development' 'topic-copilot-skills' 'topic-csharp' 'topic-dotnet' 'topic-dotnet-testing' 'topic-github-copilot' 'topic-integration-testing' 'topic-testing' 'topic-unit-testing' 'topic-xunit' 'treenod':235,243,252,263,273 'treenode-filt':234,242,251,262,272 'true':88,604,624,700,702 'tunit':5,7,10,37,41,46,221,223,285,311,313,371,389,447,452,504,527,551,586,733,797,810,824,826,831,838,846,854,861,867,874,880,886,893,900,924,926 'tunit.assertions':647 'tunit.assertions.extensions':650 'tunit.core':644 'tunit.dev':829,844,852,859,865,872,878,884,891,898,905 'tunit.dev/)':828 'tunit.dev/docs/examples/aspnet)':897 'tunit.dev/docs/examples/complex-test-infrastructure-orchestration)':904 'tunit.dev/docs/execution/engine-modes)':890 'tunit.dev/docs/execution/retrying)':877 'tunit.dev/docs/execution/timeouts)':883 'tunit.dev/docs/test-authoring/class-data-source)':851 'tunit.dev/docs/test-authoring/matrix-tests)':858 'tunit.dev/docs/test-authoring/method-data-source)':843 'tunit.dev/docs/test-lifecycle/dependency-injection)':871 'tunit.dev/docs/test-lifecycle/properties)':864 'tunit.enable':697 'tunitdependencyinject':434 'type':344,345,348,519 'unit':93,142,143,204,238,255,266 'unitpric':401 'unittest':100 'use':30,631,634,637,640,643,646,649 'user':35 'var':392,406 'vb.net':596 'verbos':673,698 'vs':449 'web':729 'webapi':655 'webapplicationfactori':23,506,523,727,784 'whenev':33 'world':128,130 'xml':603,623,701 '一次設定':456 '一致':465 '一致性':462 '三種進階資料來源':52 '不用於邏輯錯誤':482 '不需要執行時反射':565 '中使用':505 '中等優先級':101 '代表':279 '以及效能基準與並行負載測試':521 '但要注意參數數量避免爆炸性增長':717 '低優先級':123 '使用':71,224,370,530,726 '使用tunit依賴注入':385 '使用常數':213 '依賴已經透過':388 '依賴注入':372 '依賴注入或整合測試時使用':12 '依賴注入核心概念':312 '依賴注入模式':310 '依賴注入與整合測試實戰':44 '依賴注入設定':779 '依賴變更只需修改一個地方':460 '僅用於外部依賴造成的不穩定測試':479 '僅開發環境執行':124 '優先級':156 '全域鉤子':303 '前置技能':928 '動態測試發現':593 '包含':20,777,780 '原始文章':789 '參數插值':493 '參考資源':788 '反射模式':578 '另有':298 '只執行單元測試':231 '只執行高優先級測試':239 '只測試實際存在的功能':737 '只用於真正不穩定的外部依賴測試':720 '可維護性':459 '可能與實際應用程式不一致':466 '可能遺漏或錯誤建立某些依賴':475 '各只執行一次':306 '同時保持測試間的資料隔離':547 '和':595 '問題':678,686 '問題現象':612 '啟用反射模式':580 '回應驗證':516 '在':503,535,654 '型別安全':568 '執行單元測試或冒煙測試':259 '執行控制最佳實踐':718 '執行控制範例':782 '執行控制與測試品質':476 '執行控制與測試品質和':812 '執行特定功能的測試':269 '執行高優先級的單元測試':248 '基本':69 '基本驗證':102 '基礎':927 '基礎上':318 '基礎設施編排':529 '基礎設施編排範例':769 '外部檔案載入':708 '多容器編排程式碼':787 '多服務編排':26 '大幅減少啟動時間與資源消耗':546 '天挑戰':793 '失敗':616 '套件':692 '完全支援':572 '完整':522 '完整多容器編排與全域共享範例請參閱':548 '完整屬性家族與範例請參閱':307 '完整範例':495 '完整範例與比較表請參閱':64 '官方網站':827,910 '官方資源':825 '容器僅啟動一次':545 '實務建議':703 '專案':597 '專案的':656 '專注於測試邏輯':468 '層級':281 '層級管理':537 '層級與':300 '屬性名稱大小寫敏感':282 '屬性標記與測試過濾':68 '常見問題與疑難排解':610 '建構式':289 '建構式永遠最先執行':304 '建立一致的屬性命名規範':131 '建立共用網路':544 '建立複雜多服務測試環境':735 '應正確運作':386 '應能透過屬性過濾':85 '成功':618 '或條件':258 '或設定環境變數':584 '所有測試發現邏輯在編譯時產生':564 '手動依賴建立':454 '手動依賴建立比較':450 '控制':22 '提供':47 '提供完整的生命週期鉤子':286 '搭配':486,542 '支援':491,602 '支援動態產生與外部檔案載入':55 '效能優異':566 '整合':24,59,712 '整合測試':502,510,938 '整合測試實戰':815 '整合測試的特殊設定':652 '整合測試策略':725 '整合測試範例':765 '整合測試與':785 '整合與負載測試範例請參閱':524 '文件':842,850,857,863,870,876,882,889,896 '最後加上':658 '最靈活':54 '會員':412,429 '服務應為正確類型':436 '本技能內容提煉自':790 '某些依賴反射的測試模式':599 '框架保證依賴正確注入':474 '標頭檢查':520 '檔案':776 '檔案名稱':740 '檔案鎖定':481 '檢查是否有其他':689 '正確':628 '每個測試都需要手動建立':458 '比反射模式快數倍':567 '注意控制數量避免爆炸性增長':63 '涵蓋':13,514 '清理和重建':665 '測試':731 '測試可讀性':467 '測試商品':400 '測試摘要':613 '測試方法':292 '測試生命週期管理':284 '測試統計顯示異常問題':611 '測試過濾執行':222 '測試類別':137 '測試類別無法被發現':679 '為效能敏感測試設定合理上限':485 '為效能敏感的測試設定合理限制':722 '特性':451 '特色與優勢':562 '環境':181 '生命週期管理與依賴注入範例':754 '產生':783 '產生使用':771 '當需要使用':9 '的依賴注入建構在':314 '的資料驅動測試類別':774 '相容':571 '相關問題':677 '相關技能':919 '相關資源':908 '確保':626 '確保一致性':214 '確保專案完全重建':681 '確保專案檔設定正確':622 '等多容器編排':541 '管理生命週期':513 '範例':746,760 '範例程式碼':804,820 '範圍管理':470 '範本檔案':739 '系列文章':794 '組合條件':247 '組合條件必須用括號正確包圍':283 '組合測試範例':751 '網路':480 '編譯':575 '編譯時出現奇怪錯誤':687 '編譯時期產生':563 '編譯時期驗證測試配置和資料來源':569 '總計':614 '老派軟體工程師的測試修練':791 '考慮更新到相容版本':693 '而不是':227 '自動使用':598 '自動注入':391 '自動產生所有參數組合':62 '自動管理服務範圍':471 '與產品程式碼的':463 '被依賴建立程式碼干擾':469 '複雜物件':707 '解決':680,688 '解決步驟':620 '設定複雜度':455 '診斷選項':694 '說明':741 '請參閱':497 '讓整合測試可以存取':663 '讓測試報告更符合業務語言':724 '讓測試報告更貼近業務語言':494 '資料庫測試':946 '資料驅動測試':43 '資料驅動測試的選擇策略':704 '資料驅動測試與依賴注入深度實戰':799 '資料驅動測試進階技巧':45 '跨測試類別重用':713 '路徑模式':278 '輸出格式':770 '透過實作':511 '透過屬性注入系統管理複雜的依賴關係':736 '進行':507 '進行完整的':728 '進行資料驅動測試':11 '進階功能文件':837 '進階應用':42,798,811 '進階應用完整指南':8 '運用':732 '過濾':19 '過濾語法注意事項':277 '適合共享資料':710 '適合動態資料':706 '適合組合測試':716 '適合跨測試類別共享資料與':57 '適用場景':592 '避免測試不存在的端點':738 '重複使用':457 '錯誤風險':473 '鐵人賽文章':800,816 '需要修改所有使用的測試':461 '需要手動管理物件生命週期':472 '預設模式':557 '驗證':488 '驗證自動注入':435 '高優先級':84","prices":[{"id":"da0cab81-6de0-4cd7-a66c-8118ba33e8e3","listingId":"e9f29890-ced7-46c8-b36e-58d0b7330500","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"kevintsengtw","category":"dotnet-testing-agent-skills","install_from":"skills.sh"},"createdAt":"2026-04-18T23:04:18.603Z"}],"sources":[{"listingId":"e9f29890-ced7-46c8-b36e-58d0b7330500","source":"github","sourceId":"kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-advanced-tunit-advanced","sourceUrl":"https://github.com/kevintsengtw/dotnet-testing-agent-skills/tree/main/skills/dotnet-testing-advanced-tunit-advanced","isPrimary":false,"firstSeenAt":"2026-04-18T23:04:18.603Z","lastSeenAt":"2026-04-24T13:02:25.472Z"}],"details":{"listingId":"e9f29890-ced7-46c8-b36e-58d0b7330500","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"kevintsengtw","slug":"dotnet-testing-advanced-tunit-advanced","github":{"repo":"kevintsengtw/dotnet-testing-agent-skills","stars":23,"topics":["agent-skills","ai-assisted-development","copilot-skills","csharp","dotnet","dotnet-testing","github-copilot","integration-testing","testing","unit-testing","xunit"],"license":"mit","html_url":"https://github.com/kevintsengtw/dotnet-testing-agent-skills","pushed_at":"2026-03-31T07:28:56Z","description":"AI Agent Skills for .NET Testing - Based on 30-Day Testing Challenge (iThome Ironman 2025 Winner)","skill_md_sha":"55246105d1016c2d3fa17d529b1a1c4ada416351","skill_md_path":"skills/dotnet-testing-advanced-tunit-advanced/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/kevintsengtw/dotnet-testing-agent-skills/tree/main/skills/dotnet-testing-advanced-tunit-advanced"},"layout":"multi","source":"github","category":"dotnet-testing-agent-skills","frontmatter":{"name":"dotnet-testing-advanced-tunit-advanced","description":"TUnit 進階應用完整指南。當需要使用 TUnit 進行資料驅動測試、依賴注入或整合測試時使用。涵蓋 MethodDataSource、ClassDataSource、Matrix Tests、Properties 過濾。包含 Retry/Timeout 控制、WebApplicationFactory 整合、Testcontainers 多服務編排。\nMake sure to use this skill whenever the user mentions TUnit advanced, MethodDataSource, ClassDataSource, Matrix Tests, TUnit dependency injection, TUnit Retry/Timeout, or TUnit WebApplicationFactory, even if they don't explicitly ask for TUnit advanced features.\nKeywords: TUnit advanced, TUnit 進階, MethodDataSource, ClassDataSource, Matrix Tests, MatrixDataSource, MicrosoftDependencyInjectionDataSource, Property, Retry, Timeout, 資料驅動測試, 測試過濾, WebApplicationFactory TUnit, 多容器編排"},"skills_sh_url":"https://skills.sh/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-advanced-tunit-advanced"},"updatedAt":"2026-04-24T13:02:25.472Z"}}