|
| 1 | +# Serde Format Test Plan |
| 2 | + |
| 3 | +This document captures test cases that are format-agnostic and should be implemented across all Serde serialization formats (JSON, XML, TOML, etc.). |
| 4 | + |
| 5 | +## Exception Handling |
| 6 | + |
| 7 | +### Deserialization exceptions should not be hidden by Dispose exceptions |
| 8 | + |
| 9 | +**Scenario:** When deserialization fails partway through parsing, the `Dispose` method may also fail (e.g., because the reader isn't at the expected position). The original deserialization exception should be propagated to the caller, not hidden by a secondary exception from `Dispose`. |
| 10 | + |
| 11 | +**Test approach:** |
| 12 | +- Provide malformed input that causes deserialization to fail mid-parse |
| 13 | +- Ensure the input also leaves the deserializer in a state where `Dispose` would throw |
| 14 | +- Assert that the original parsing exception is thrown, not a Dispose-related exception |
| 15 | + |
| 16 | +**Example (XML):** |
| 17 | +```xml |
| 18 | +<BoolStruct> |
| 19 | + <BoolField>notaboolean</BoolField> |
| 20 | + <ExtraContent>causes Dispose to fail</ExtraContent> |
| 21 | +</BoolStruct> |
| 22 | +``` |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## Round-Trip Consistency |
| 27 | + |
| 28 | +### Serialize then deserialize should produce equal objects |
| 29 | + |
| 30 | +**Scenario:** Any serializable object should survive a round-trip through serialization and deserialization unchanged. |
| 31 | + |
| 32 | +**Test approach:** |
| 33 | +- Create an instance with known values |
| 34 | +- Serialize to string |
| 35 | +- Deserialize back to object |
| 36 | +- Assert equality with original |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## Null and Optional Handling |
| 41 | + |
| 42 | +### Null values should serialize/deserialize correctly |
| 43 | + |
| 44 | +**Scenario:** Nullable fields and reference types set to null should be handled consistently. |
| 45 | + |
| 46 | +**Test approach:** |
| 47 | +- Test nullable value types (`int?`, `bool?`) |
| 48 | +- Test nullable reference types (`string?`, custom classes) |
| 49 | +- Verify round-trip preserves null vs default distinction where applicable |
| 50 | + |
| 51 | +### Missing fields during deserialization |
| 52 | + |
| 53 | +**Scenario:** When deserializing, fields missing from the input should receive appropriate default values or throw meaningful errors. |
| 54 | + |
| 55 | +**Test approach:** |
| 56 | +- Deserialize input missing required fields |
| 57 | +- Deserialize input missing optional fields |
| 58 | +- Verify behavior matches expectations (default value vs exception) |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## Edge Cases |
| 63 | + |
| 64 | +### Empty collections |
| 65 | + |
| 66 | +**Scenario:** Empty arrays, lists, and dictionaries should serialize and deserialize correctly. |
| 67 | + |
| 68 | +**Test approach:** |
| 69 | +- Serialize object with empty `[]` or `{}` |
| 70 | +- Deserialize and verify empty collection is restored |
| 71 | + |
| 72 | +### Nested types |
| 73 | + |
| 74 | +**Scenario:** Deeply nested object graphs should serialize/deserialize correctly. |
| 75 | + |
| 76 | +**Test approach:** |
| 77 | +- Test 2-3 levels of nesting |
| 78 | +- Verify all nested properties survive round-trip |
| 79 | + |
| 80 | +### Special characters in strings |
| 81 | + |
| 82 | +**Scenario:** Strings containing format-specific special characters should be properly escaped. |
| 83 | + |
| 84 | +**Test approach:** |
| 85 | +- Include characters that require escaping in the format (e.g., `<`, `>`, `&` for XML; `"`, `\` for JSON) |
| 86 | +- Verify round-trip preserves exact string content |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## Numeric Boundaries |
| 91 | + |
| 92 | +### Integer boundary values |
| 93 | + |
| 94 | +**Scenario:** Min/max values for all integer types should serialize correctly. |
| 95 | + |
| 96 | +**Test approach:** |
| 97 | +- Test `byte.MaxValue`, `int.MinValue`, `long.MaxValue`, etc. |
| 98 | +- Verify no overflow or precision loss |
| 99 | + |
| 100 | +### Floating point special values |
| 101 | + |
| 102 | +**Scenario:** Special floating point values should be handled appropriately. |
| 103 | + |
| 104 | +**Test approach:** |
| 105 | +- Test `double.NaN`, `double.PositiveInfinity`, `double.NegativeInfinity` |
| 106 | +- Document expected behavior (some formats may not support these) |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## Enum Handling |
| 111 | + |
| 112 | +### Enum serialization format |
| 113 | + |
| 114 | +**Scenario:** Enums should serialize as their string name (not numeric value) by default. |
| 115 | + |
| 116 | +**Test approach:** |
| 117 | +- Serialize enum value |
| 118 | +- Verify output contains name, not integer |
| 119 | +- Verify deserialization from name works |
| 120 | + |
| 121 | +### Unknown enum values during deserialization |
| 122 | + |
| 123 | +**Scenario:** Deserializing an unrecognized enum string should produce a clear error. |
| 124 | + |
| 125 | +**Test approach:** |
| 126 | +- Attempt to deserialize invalid enum string |
| 127 | +- Verify meaningful exception is thrown |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +## Adding New Test Cases |
| 132 | + |
| 133 | +When adding a test case to this plan: |
| 134 | +1. Describe the scenario in format-agnostic terms |
| 135 | +2. Provide a concrete test approach |
| 136 | +3. Note any format-specific considerations |
| 137 | +4. Implement the test in all format libraries |
0 commit comments