Jenkins任务执行完所有单元测试后异常终止,求排查思路
Jenkins已完成所有单元测试的执行,但最终输出中出现如下信息:
……
Passed test_name……
Closing app with package full name 'app_full_name'.
The active test run was aborted. Reason: One or more errors occurred.
Closing app with package full name 'app_full_name'
……
Hey there, let's break down how to troubleshoot this frustrating issue—your Jenkins-run UWP unit tests are passing all cases but still aborting at the end with that vague "one or more errors" message. Your hunch about the app UI window not closing is a solid starting point, but let's cover all actionable angles to get to the root cause:
Dig into full, verbose Jenkins logs
The snippet you shared only shows a small slice of what's happening. Enable verbose logging for your Jenkins job (check the job configuration's "Log Level" settings) to capture every detail leading up to the abort. Specifically look for:- Hidden error messages or stack traces right before the "active test run was aborted" line
- Timestamps around the app closing attempts to spot delays or hangs
- Any warnings about UWP package termination failures from the test runner
Add detailed logging to your UWP test app's cleanup logic
Most UWP test frameworks let you inject custom logging into teardown methods. Add logs to confirm:- When the test
Teardownmethod starts and finishes - Whether calls like
Application.Current.Exit()orWindow.Close()execute without exceptions - If there are unhandled exceptions in the app's main UI thread that don't bubble up to the test runner
Save these logs to your Jenkins workspace so you can review them post-build.
- When the test
Verify your cleanup logic works locally first
Test your UWP unit tests on your local machine (outside Jenkins) and manually check if the app window closes properly after all tests run. If it hangs locally too, the issue is with your test code, not Jenkins. Fix the cleanup logic first—make sure you explicitly close all opened windows, dispose of UI resources, and avoid relying on implicit garbage collection to shut down the app.Check Jenkins agent permissions and session state
Jenkins agents running as Windows services often lack interactive desktop access, which can break UWP app window management:- Try running the Jenkins agent as a local user with interactive desktop rights (instead of a service)
- Ensure the agent user has permission to terminate UWP processes—test this by manually killing the
app_full_nameprocess via Task Manager as that user - Disable screen savers, power locks, or remote desktop disconnects on the agent machine, as these can interfere with UI window operations
Add a forced cleanup script to your Jenkins job
As a test to confirm your window-closing theory, add a PowerShell step right after your test run to force-kill the UWP app:# Kill the UWP app by package name (replace with your actual package name) $appPackage = Get-AppxPackage *app_full_name* if ($appPackage) { Stop-Process -Name $appPackage.PackageFamilyName -Force -ErrorAction SilentlyContinue Write-Host "Forcibly terminated UWP app package: $($appPackage.Name)" }If the abort stops happening after adding this, it confirms the app wasn't closing on its own, and you can focus on fixing the test's native cleanup logic.
Update your UWP test framework and Jenkins plugins
Older versions of the UWP Unit Test Framework (and corresponding Jenkins plugins) had known issues with test run cleanup when UI elements were involved. Make sure you're using the latest stable versions of both to rule out bugs that have already been fixed.
内容的提问来源于stack exchange,提问作者gmojunior

