Improved Test Evidence with Crash-Resilient TRX

Continuous Integration and Continuous Deployment (CI/CD) pipelines are only as reliable as the feedback they provide. When a test process unexpectedly terminates, a simple red build status offers little insight into what went wrong. Developers need to know which tests completed successfully, which were in progress, and precisely where the failure occurred. Microsoft.Testing.Platform (MTP) has addressed this critical gap with its crash-resilient Test Results eXtended (TRX) reporting, introduced starting with version 2.3.

Traditionally, TRX files were finalized only upon a clean shutdown of the test execution environment. This meant that any abrupt termination—whether due to an infrastructure failure, an unhandled exception in the test runner itself, or a host operating system crash—would result in a lost or incomplete test record. This left developers staring at an opaque failure, forcing them to guess at the state of their test suite at the moment of collapse. The new crash-resilient TRX feature fundamentally changes this by streaming results as tests execute, ensuring that completed test outcomes are persisted even if the host dies.

This shift transforms an infrastructure failure from an unrecoverable data loss event into a valuable debugging artifact. The persisted partial TRX file, combined with a new crash-sequence artifact, provides a much clearer picture of the test run's state. This evidence can then be archived and inspected, enabling more efficient root cause analysis.

Understanding the Mechanism

The core innovation lies in how MTP's TRX reporter now operates. Instead of buffering all results and writing them to disk only at the very end of a test session, the reporter streams completed test results to the TRX file in near real-time. This means that as soon as a test method finishes executing and its outcome (pass, fail, skip, etc.) is determined, that information is written to the `.trx` file.

This streaming approach has a significant implication: even if the test host process is terminated abruptly—before it can perform its usual cleanup routines—the results that have already been streamed remain available. The resulting `.trx` file might be partial, but it is still a valid XML document containing all the data that was successfully written. This partial report is far more useful than no report at all.

To complement the partial TRX, MTP also generates a crash-sequence artifact. This log specifically details the order in which tests completed and, crucially, identifies which test was actively running or was about to start when the host process terminated. This sequence log acts as a pointer, directing developers to the most likely point of failure. By correlating the last successfully recorded test in the TRX file with the test identified in the crash-sequence log, engineers can quickly narrow down the scope of their investigation.

Diagram illustrating the flow of test results from execution to persisted TRX file.

Practical Implications for CI/CD

For teams relying on automated testing within their CI/CD pipelines, this feature is a significant quality-of-life improvement. Consider a scenario where a build agent encounters an unexpected resource exhaustion, a network interruption, or a bug in the test runner itself. In older systems, such an event would leave the pipeline in an indeterminate state, with no clear record of test progress. Developers would then have to manually re-run tests, often in larger batches, to pinpoint the regression or failure.

With crash-resilient TRX, the pipeline can capture the state of the test run up to the point of failure. Automated systems can be configured to collect these partial TRX files and the crash-sequence logs as build artifacts. This allows for immediate post-mortem analysis without requiring a full re-run of potentially lengthy test suites. If a test failed, the logs will show its outcome. If a test was interrupted mid-execution, the sequence log will highlight it.

This capability is particularly valuable for long-running test suites or those that are prone to intermittent failures. It provides a historical record that aids in understanding the stability trends of the codebase over time, even in the face of infrastructure volatility. The ability to reliably archive evidence of test execution, regardless of host stability, strengthens the overall robustness and debuggability of automated testing frameworks.

Validating Partial TRX and Sequence Logs

The effectiveness of this feature hinges on the validity of the partial TRX files and the accuracy of the sequence logs. Microsoft has ensured that the streamed results adhere to the TRX schema, meaning that standard tools designed to parse TRX files can still process the partial reports. While some fields might be incomplete (e.g., final execution time if the process crashed), the core information about test outcomes, names, and associated messages remains intact for completed tests.

The crash-sequence artifact is typically a simple text file, making it easily inspectable. A runnable sample provided by Microsoft demonstrates how to intentionally trigger a host crash during a test run and then examine both the generated partial TRX and the sequence log. This sample confirms that the partial TRX is parsable and that the sequence log accurately points to the interrupted test, validating the feature's practical utility.

This level of detail transforms troubleshooting. Instead of relying on guesswork or extensive manual re-runs, engineers can directly examine the evidence left behind by a failed execution. This accelerates the feedback loop, reduces developer frustration, and ultimately contributes to faster and more reliable software delivery.