Table of Contents

Class LogAssertionsTestLifetimeAttribute

Namespace
LogAssertions.TUnit
Assembly
LogAssertions.TUnit.dll

Lets LogAssertions see when each test starts and ends. Apply it once to the test project:

[assembly: LogAssertions.TUnit.LogAssertionsTestLifetime]

It enables DumpToTestOutputOnFailure(), which throws without it, and makes the built-in test-output tee exact: a record logged after its test has ended is not written into that test's report.

[AttributeUsage(AttributeTargets.Assembly)]
public sealed class LogAssertionsTestLifetimeAttribute : Attribute, ITestStartEventReceiver, ITestEndEventReceiver, IEventReceiver
Inheritance
LogAssertionsTestLifetimeAttribute
Implements
ITestStartEventReceiver
ITestEndEventReceiver
IEventReceiver
Inherited Members

Remarks

TUnit offers no public way for code inside a test to observe that test's end, so the package needs this one line of opt-in. The attribute receives TUnit's test start (before the [Before(Test)] hooks) and test end (after the [After(Test)] hooks) for every test of the assembly, and once per attempt for a retried test.

Without it, the tee falls back to a coarser rule: a record logged where no test is current goes to the test that built the tee only until that test has a result, and a record logged on a test's own flow always goes to that test.

All state is static and keyed weakly by the test's TUnit.Core.TestContext, so nothing outlives the test.