-
Notifications
You must be signed in to change notification settings - Fork 0
EN 07_test_specification
🇺🇸 English | 🇯🇵 日本語 | Introduction
This document specifies the formal testing standards for the DependencyPropertyGenerator (Kassyi.Generators.DependencyProperty). It defines the multi-tier testing strategy, quality targets, combinatorial matrix parameters, test case catalogs, execution environments, and strict verification criteria. All test IDs map directly to the C# TestCategoryNames constants.
This architecture uses a 4-tier test pyramid to rigorously validate the Roslyn Source Generator across compile-time metaprogramming, cross-platform environments, incremental caching, and runtime execution.
flowchart TD
subgraph TestPyramid ["Testing Pyramid Hierarchy"]
D["4. Performance & Caching (Benchmarks)<br>Initial generation / Cache hits / Zero-allocation (0 B)"]
C["3. Runtime Integration (IntegrationTests)<br>UI control instantiation / SetValue & GetValue / Callbacks"]
B["2. Syntax & Snapshot Coverage (SnapshotTests)<br>Full Combinatorial (576 cases) / Language Orthogonality / Diagnostics"]
A["1. Unit Tests (UnitTests / Extensions)<br>FileName sanitizer / String extensions / DTO mappings"]
end
A --> B
B --> C
C --> D
| Tier | Project name | Responsibilities | Primary technologies |
|---|---|---|---|
| Unit tests |
Tests.Extensions / Unit |
Validates utility logic, file sanitization, and boundary string extensions. | MSTest |
| Syntax and generation | SnapshotTests |
Verifies C# language orthogonality, full combinatorial matrix, and Roslyn diagnostics. | MSTest, Verify.MSTest, Roslyn Testing |
| Runtime integration | IntegrationTests |
Tests runtime execution and state transitions on actual UI controls. | MSTest, Avalonia (Headless and real instances) |
| Performance and cache | Benchmarks |
Measures initial throughput, incremental pipeline cache hits, and memory allocations. | BenchmarkDotNet, MemoryDiagnoser |
Warning
Source Generators are highly sensitive to environment variations (OS, path separators, line endings). You must run and validate all tests against the specified multi-platform conditions to ensure compliance.
The target host OS and environment conditions are as follows:
-
Windows: Windows Server or Windows 11 (Line endings:
CRLF, Path separator:\or entity reference\) -
Linux: Ubuntu Latest (Line endings:
LF, Path separator:/) -
macOS: macOS Latest (Line endings:
LF, Path separator:/)
The build requires the .NET 9.0 SDK and uses C# 13.0 Preview language features. The generator targets WPF (.NET Framework 4.8 / .NET Core 3.1 / .NET 5 through 9), Uno Platform (UWP and WinUI), .NET MAUI (.NET 7.0+), and Avalonia UI (11.0+).
All compilation tests run purely in-memory via CSharpCompilation without relying on disk states or shared mutable statics. The test runner tears down generator instances and syntax trees independently per test case, guaranteeing thread safety under MSTest [Parallelize] configurations.
| Metric | Target | Pass criteria and remarks |
|---|---|---|
| Line coverage | >= 90% | Measures the coverage of the core generator engine (Kassyi.Generators.DependencyProperty). |
| Branch coverage | >= 85% | Evaluates coverage across attribute parsing, type inference, and syntax branches. |
| Full matrix coverage | 100% (576/576) | Validates all valid permutations of parameters and modifiers. |
| Compilation errors | 0 errors | Ensures a Severity = Error count of zero across all generated code. |
| Incremental latency | <= 0.5 ms | Measures pipeline cache-hit execution latency during non-structural edits. |
| Cache heap allocations | 0 bytes | Requires exactly zero GC heap allocation during incremental cache hits. |
The test suite validates all permutations of dependency property attributes and class definitions. It executes 576 independent test cases via MSTest [DynamicData] (Category: Matrix, Test ID: Matrix-001).
-
Framework (5):
Wpf,Uno,UnoWinUi,Maui,Avalonia -
AttrType (2):
Normal,Attached -
ClassMode (4):
PublicClass,InternalGenericClass,PublicRecord,StaticClass -
PropType (4):
Int,NullableInt,String,GenericList -
ReadOnlyMode (2):
False,True -
DefaultMode (3):
None,Literal,Expression -
DirectMode (2):
False,True
Note
Framework limitations explicitly exclude certain permutations:
-
DirectMode.Trueis only valid withFramework.AvaloniaandAttrType.Normal. -
PublicRecordandStaticClassare restricted toAttrType.Attached. - To prevent reference-sharing bugs (
DPG0004),PropType.GenericListstrictly requiresDefaultMode.None.
The suite verifies that the generator output does not interfere with C# language features (C# 8.0 through C# 13.0) (Category: Language).
(Note: The exhaustive list of 32 language feature tests remains architecturally identical to the previous specification.)
Validates attached property constraints and callback wiring.
-
Attached-002: Restricts
Setaccessor visibility tointernalorprivatewhenIsReadOnly = true. -
Attached-003: Constrains target parameter typing based on
BrowsableForType. - Attached-008: Prevents circular references during self-referential generic typing.
Validates event generation based on the WPF routing infrastructure.
-
Routed-003: Prevents duplicate
public static partial classmodifiers on static classes. -
Routed-006: Selectively suppresses
CS0436conflicts for generated attributes.
Validates weak event manager code generation to prevent memory leaks.
Validates metadata rewriting (OverrideMetadata) and shared properties (AddOwner) across inheritance trees.
-
Doc-001: Guarantees all code blocks in
README.mdcompile and generate cleanly.
Important
The generator must emit clean compile-time diagnostics (for example, DPG0001, DPG0004) for invalid user input without crashing the pipeline (Test Category: Error).
| Test ID | Diagnostic ID | Severity | Trigger condition |
|---|---|---|---|
| Error-001 | DPG0001 |
Error | Non-existent or invalid signature for an explicit OnChanged callback |
| Error-004 | DPG0003 |
Error | Using a ref struct type as a property type |
| Error-005 | DPG0004 |
Error | Reference type default value without a callback or expression |
| Error-010 | DPG0007 |
Error | Callback matching the naming convention but with an unsupported signature |
Tests verify that the generated code builds into functional assemblies and operates correctly within live Avalonia and WinUI environments.
-
Integration-001 (State): Setting a value securely updates the
GetValue(...)return. -
Integration-002 (Callbacks): Modifications strictly invoke the
partial void OnIsSpinningChanged(...)method. - Integration-004 (Coerce): Verifies values are correctly clamped to prevent infinite loops or re-entrancy.
Tip
Validates sub-millisecond responsiveness during IDE keystrokes using BenchmarkDotNet.
- Perf-001: Execution latency must remain <= 0.5 ms during cache hits.
- Perf-002: GC heap allocation must be exactly 0 bytes during cache hits.
-
Unit-001 (Sanitization): Safely converts invalid filesystem characters (
<,>,?) to_. -
Unit-002 (Extensions): Securely handles edge cases when injecting the
global::namespace prefix.
The CI pipeline runs unconditionally across Windows, Ubuntu, and macOS.
dotnet test Kassyi.Generators.DependencyProperty.sln --configuration ReleasePRs must pass CombinatorialMatrixTests (576 cases) and all IntegrationTests. Any .verified.cs snapshot diffs require mandatory reviewer approval.
Tip
Agentic ground truth Autonomous agents (AI assistants) modifying tests must strictly follow these structural boundaries.
-
Compilation and output malformations: Add a test to
SnapshotTests(for example,AttachedTests.cs) and update the.verified.cssnapshot. -
Runtime and event failures: Add a test to
IntegrationTests. Instantiate the actual UI control and assertGetValueandSetValuebehaviors directly. -
New language features and attributes: Expand the
CombinatorialMatrixTestsfactors. Applyyield breakconstraints if permutations explode redundantly. -
Diagnostics modifications: Add tests to
ErrorTests.cs. Verify only the emittedDiagnosticcount and message; do not assert source generation, as generation is structurally bypassed upon errors.
This wiki is automatically synchronized from spec/ in the repository.
- Introduction
- 01. FAQ & Design Rationale
- 02. Foundation & Domain
- 03. Pipeline Architecture
- 04. Framework Strategies
- 05. Synthesis & Performance
- 06. Complexity Model
- 07. Test Specification
- 08. Diagnostics Reference
- 概要
- 01. 設計思想とFAQ
- 02. 基盤とドメイン
- 03. パイプライン構造
- 04. フレームワーク別生成仕様
- 05. コード生成と最適化
- 06. 計算量モデル
- 07. テスト仕様書
- 08. 診断機能リファレンス