From cd65f4be351f05df6ea064b690a2f87123d7ecb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Thu, 11 Dec 2025 11:18:29 +0100 Subject: [PATCH] Update MSTest v4 migration documentation Updated the date for MSTest v4 migration and added information about accessing non-existing properties in TestContext.Properties. --- .../unit-testing-mstest-migration-v3-v4.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/core/testing/unit-testing-mstest-migration-v3-v4.md b/docs/core/testing/unit-testing-mstest-migration-v3-v4.md index f542536a8d036..a597c4d5cf679 100644 --- a/docs/core/testing/unit-testing-mstest-migration-v3-v4.md +++ b/docs/core/testing/unit-testing-mstest-migration-v3-v4.md @@ -3,7 +3,7 @@ title: MSTest migration from v3 to v4 description: Learn about migrating to MSTest v4. author: Youssef1313 ms.author: ygerges -ms.date: 07/22/2025 +ms.date: 12/11/2025 --- # Migrate from MSTest v3 to v4 @@ -99,6 +99,20 @@ public static void ClassCleanup(TestContext testContext) Previously, `TestContext.Properties` was an `IDictionary`. To provide better typing, it's now `IDictionary`. +#### Accessing non-existing property + +Accessing a non-existing property in the dictionary will now throw `KeyNotFoundException` rather than returning null. + +```csharp +// in MSTest 3.x +var value = TestContext.Properties["NonExistent"]; // Returns null + +// in MSTest 4.x +var value = TestContext.Properties["NonExistent"]; // Throws KeyNotFoundException +``` + +To check for existence of a property, use `TryGetValue` or `ContainsKey` methods. + If you have calls to `TestContext.Properties.Contains`, update them to `TestContext.Properties.ContainsKey`. ### TestTimeout enum is removed