Skip to content

Commit cd65f4b

Browse files
authored
Update MSTest v4 migration documentation
Updated the date for MSTest v4 migration and added information about accessing non-existing properties in TestContext.Properties.
1 parent 589188f commit cd65f4b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/core/testing/unit-testing-mstest-migration-v3-v4.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: MSTest migration from v3 to v4
33
description: Learn about migrating to MSTest v4.
44
author: Youssef1313
55
ms.author: ygerges
6-
ms.date: 07/22/2025
6+
ms.date: 12/11/2025
77
---
88

99
# Migrate from MSTest v3 to v4
@@ -99,6 +99,20 @@ public static void ClassCleanup(TestContext testContext)
9999

100100
Previously, `TestContext.Properties` was an `IDictionary`. To provide better typing, it's now `IDictionary<string, object>`.
101101

102+
#### Accessing non-existing property
103+
104+
Accessing a non-existing property in the dictionary will now throw `KeyNotFoundException` rather than returning null.
105+
106+
```csharp
107+
// in MSTest 3.x
108+
var value = TestContext.Properties["NonExistent"]; // Returns null
109+
110+
// in MSTest 4.x
111+
var value = TestContext.Properties["NonExistent"]; // Throws KeyNotFoundException
112+
```
113+
114+
To check for existence of a property, use `TryGetValue` or `ContainsKey` methods.
115+
102116
If you have calls to `TestContext.Properties.Contains`, update them to `TestContext.Properties.ContainsKey`.
103117

104118
### TestTimeout enum is removed

0 commit comments

Comments
 (0)