我遇到了成功执行测试后 XCTest 结果未在 Azure DevOps 中发布的问题。 XCTest 案例在 Xcode 中针对 iOS 运行,并且测试成功通过。但是,当尝试在 Azure DevOps 中发布结果时,JUnit 文件似乎为空。
似乎正在生成 JUnit 文件,但 JUnit 中的 Azure DevOps 并未获取结果。
这是日志的片段:
测试结果存储在build/reports/junit.xml中
Run Attachments will be stored in LogStore
[debug]Object of TestRunPublisher created.
[debug]Object of TestLogStore created.
[debug]Object of JUnitResultParser created.
[debug]Entering ParseTestResultFiles
[debug]runContext.ReleaseURI is null
[debug]runContext.ReleaseEnvironmentUri is null
**[debug]Reading test results from file '/Users/runner/work/1/s/build/reports/junit.xml'.
[debug]Total test results: 0.**
No Result Found to Publish '/Users/runner/work/1/s/build/reports/junit.xml'.
[debug]Leaving ParseTestResultFiles
我已按照在管道 YAML 文件中配置测试报告的常规步骤进行操作,并且 JUnit 文件的路径是正确的。
以下是 YAML 文件的摘录:
steps:
- task: Xcode@5
displayName: 'Run XCTest'
inputs:
actions: test
configuration: Debug
sdk: iphonesimulator
xcWorkspacePath: '**/MYscheme.xcodeproj/project.xcworkspace'
scheme: MYscheme
signingOption: auto
teamId:XXXXX
destinationPlatformOption: custom
destinationPlatform: iOS
destinationSimulators: 'iPhone 13 Pro'
publishJUnitResults: true
testRunTitle: TestResults
steps:
- task: PublishPipelineArtifact@1
displayName: 'Publish Pipeline Artifact'
inputs:
targetPath: '$(Build.SourcesDirectory)/build/reports/'
artifact: JUnitResults
I would appreciate any insights or suggestions on why the test results might not be getting picked up and published in Azure DevOps despite the successful XCTest execution. Thank you in advance for your assistance!
所以我刚刚使用 Fastlane 和 Azure 完成了这项工作。我的测试没有发布,当我遇到错误时,它会在管道中显示为警告。我不知道这是否与您的问题相同,但这就是我使我的 iOS E2E 测试报告显示在 Azure 中的方法:
这是 iOS 测试的通道,您需要调整
output_
参数,以确保您知道报告的类型以及它将存储在哪里。
desc 'Running Virtual Device iOS Specific Tests'
lane :e2eIosSpecificTests do
desc('Start the tests')
scan(
workspace: "./iosApp/<your project>.xcodeproj/project.xcworkspace",
scheme: "iosApp",
devices: ["iPhone 15 Pro"],
output_directory: ENV['SCAN_OUTPUT_DIR'], # Use environment variable for directory
output_types: "junit",
output_files: "ios-test-results.xml"
)
end
这是包含管道 iOS 阶段的
.yml
文件的一部分:
- stage: NewiOSE2EPAStagingX86
condition: always()
pool:
name: $(agentPool)
demands:
- Agent.Name -equals $(agentName)
jobs:
- job: BuildAndTest
displayName: Build and Test
steps:
- script: 'bundle exec fastlane ios e2eIosSpecificTests'
displayName: Execute iOS Simulator E2E Tests on PA Staging
workingDirectory: $(workingDirectory)
env:
SCAN_OUTPUT_DIR: "$(Agent.TempDirectory)/TestResults" # Use the agent's temporary directory
- task: PublishBuildArtifacts@1
condition: always()
- task: PublishTestResults@2
displayName: Publish Test Results
condition: always()
inputs:
searchFolder: '$(Agent.TempDirectory)/TestResults' # Using the dynamic agent temp directory
testResultsFiles: '**/ios-test-results.xml'
testResultsFormat: 'JUnit' # Options: JUnit, NUnit, VSTest, xUnit, cTest
publishRunAttachments: true # Optional: publishes screenshots/logs attached to test results
mergeTestResults: true # Optional
failTaskOnFailedTests: true # Optional
testRunTitle: iOS E2E Tests # Optional
在
BuildAndTest
作业中,我们定义 SCAN_OUTPUT_DIR
环境变量,Fastlane 将使用该变量作为 output_directory
的参数。然后,我们通过 PublishBuildArtifacts
告诉 PublishTestResults
和 condition: always()
步骤运行,无论前面步骤的结果如何。最后,我们指示 PublishTestResults
搜索我们在 SCAN_OUTPUT_DIR
中定义的文件夹以获取测试结果,并为其指定 testResultsFiles
的名称(如果您有更多,您可以提供类似 /.xml 的模式)比 1 个以不同名称发布的测试结果)。我们还告诉它结果应该以什么类型的格式显示(在我们的例子中,我们希望它作为 JUnit 测试结果)。
希望这可以帮助您解决您的问题。