Skip to content

Cleanup AssemblyInitialize failure handling#7547

Merged
Youssef1313 merged 4 commits intomainfrom
dev/ygerges/asminit-refactor
Mar 13, 2026
Merged

Cleanup AssemblyInitialize failure handling#7547
Youssef1313 merged 4 commits intomainfrom
dev/ygerges/asminit-refactor

Conversation

@Youssef1313
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings March 13, 2026 07:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors MSTest adapter assembly-initialize failure handling so initialization failures are returned as TestResult data instead of being propagated via thrown exceptions, aligning the runner and unit tests with the new behavior.

Changes:

  • Change TestAssemblyInfo.RunAssemblyInitializeAsync to return a TestResult and store initialization failures as TestFailedException.
  • Update UnitTestRunner to consume the returned TestResult (removing special-case catching of TestFailedException for assembly init).
  • Update unit tests to assert on TestResult.TestFailureException rather than expecting exceptions to be thrown.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs Updates tests to validate returned TestResult and failure exception contents instead of exception throwing.
src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs Uses the TestResult returned by assembly initialization and attaches captured logs/errors/trace.
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestAssemblyInfo.cs Changes assembly init API to return TestResult and normalizes stored init failures to TestFailedException.

You can also share your feedback on Copilot code review. Take the survey.

Youssef1313 and others added 2 commits March 13, 2026 09:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 13, 2026 11:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors AssemblyInitialize failure handling in the MSTest adapter execution flow by returning a TestResult from RunAssemblyInitializeAsync instead of throwing, and updates the runner/tests accordingly.

Changes:

  • Change TestAssemblyInfo.RunAssemblyInitializeAsync to return a TestResult and cache failures as TestFailedException.
  • Update UnitTestRunner to consume the returned TestResult rather than relying on catching TestFailedException.
  • Update TestAssemblyInfoTests to assert on returned TestResult.TestFailureException instead of expecting exceptions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs Updates unit tests to validate returned TestResult/failure exception rather than thrown exceptions.
src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs Adjusts assembly-initialize invocation to use the returned TestResult.
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestAssemblyInfo.cs Implements new RunAssemblyInitializeAsync contract returning TestResult and normalizes failures to TestFailedException.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean refactoring — removing the throw/catch dance in favor of returning TestResult directly simplifies the control flow nicely and avoids exception overhead on the normal failure path. The GetTestFailedExceptionFromAssemblyInitializeException extraction keeps the wrapping logic clean, and the property type narrowing (Exception?TestFailedException?) is safe since TestAssemblyInfo is internal sealed. The hasExecuted guard addition in RunAssemblyInitializeShouldPassOnTheTestContextToAssemblyInitMethod is a nice touch.

Left a couple of minor nits on the tests.

Copy link
Contributor

Copilot AI commented Mar 13, 2026

@Youssef1313 I've opened a new pull request, #7550, to work on those changes. Once the pull request is ready, I'll request review from you.

…eAsync` tests (#7550)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
@Youssef1313 Youssef1313 enabled auto-merge (squash) March 13, 2026 15:16
@Youssef1313 Youssef1313 merged commit a5ed69e into main Mar 13, 2026
10 checks passed
@Youssef1313 Youssef1313 deleted the dev/ygerges/asminit-refactor branch March 13, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants