Skip to content

Commit a27d40e

Browse files
committed
docs: add remarks explaining when class instances change
1 parent a2d4a3a commit a27d40e

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

TUnit.Engine/Extensions/TestContextExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ internal static class TestContextExtensions
3636
/// <summary>
3737
/// Checks if the class instance has changed since caches were built, and invalidates if needed.
3838
/// </summary>
39+
/// <remarks>
40+
/// Class instances change in these scenarios:
41+
/// - Test retries: A new instance is created for each retry attempt
42+
/// - Keyed test instances: Different data combinations may use different instances
43+
/// When this happens, eligible event objects may include the new instance (if it implements
44+
/// event receiver interfaces), so all caches must be invalidated and rebuilt.
45+
/// </remarks>
3946
private static void InvalidateCachesIfClassInstanceChanged(TestContext testContext)
4047
{
4148
var currentClassInstance = testContext.Metadata.TestDetails.ClassInstance;
4249
if (testContext.CachedClassInstance != null &&
4350
!ReferenceEquals(testContext.CachedClassInstance, currentClassInstance))
4451
{
45-
// Class instance changed (e.g., on retry), invalidate all caches
52+
// Class instance changed - invalidate all caches so they're rebuilt with the new instance
4653
testContext.InvalidateEventReceiverCaches();
4754
}
4855
testContext.CachedClassInstance = currentClassInstance;

0 commit comments

Comments
 (0)