You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行测试计划迁移JSON脚本时遇'Sequence contains more than one element'错误求解决

"Sequence contains more than one element" 错误排查与解决(测试计划迁移场景)

问题场景

运行测试计划迁移JSON脚本时,触发错误提示:Sequence contains more than one element

迁移配置脚本

{
"ChangeSetMappingFile": null,
"Source": {
"$type": "TfsTeamProjectConfig",
"Collection": "http://alpvbhnptfsa01.ent.bhicorp.com:8080/tfs/XXX/",
"Project": "XXXXX",
"ReflectedWorkItemIDFieldName": "Microsoft.VSTS.Build.IntegrationBuild",
"AllowCrossProjectLinking": false,
"AuthenticationMode": "Prompt",
"PersonalAccessToken": "",
"PersonalAccessTokenVariableName": "",
"LanguageMaps": {
"AreaPath": "Area",
"IterationPath": "Iteration"
}
},
"Target": {
"$type": "TfsTeamProjectConfig",
"Collection": "https://dev.azure.com/XXXXXXXX/",
"Project": "XXXXXXXXXX",
"ReflectedWorkItemIDFieldName": "Custom.ReflectedWorkItemId",
"AllowCrossProjectLinking": false,
"AuthenticationMode": "AccessToken",
"PersonalAccessToken": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"PersonalAccessTokenVariableName": "",
"LanguageMaps": {
"AreaPath": "Area",
"IterationPath": "Iteration"
}
},
"FieldMaps": [
{
"$type": "MultiValueConditionalMapConfig",
"WorkItemTypeName": "*",
"sourceFieldsAndValues": { "System.State": "New" },
"targetFieldsAndValues": { "Microsoft.VSTS.Common.ActivatedDate": null, "Microsoft.VSTS.Common.ActivatedBy": null, "Microsoft.VSTS.Common.ClosedDate":null, "Microsoft.VSTS.Common.ClosedBy": null}
}
],
"GitRepoMapping": null,
"LogLevel": "Debug",
"CommonEnrichersConfig": null,
"Processors": [
{
"$type": "TestVariablesMigrationConfig",
"Enabled": true
},
{
"$type": "TestConfigurationsMigrationConfig",
"Enabled": true
},
{
"$type": "TestPlansAndSuitesMigrationConfig",
"Enabled": true,
"PrefixProjectToNodes": false,
"OnlyElementsWithTag": null,
"TestPlanQueryBit": null,
"RemoveAllLinks": false,
"MigrationDelay": 0,
"UseCommonNodeStructureEnricherConfig": false,
"NodeBasePaths": [],
"AreaMaps": null,
"IterationMaps": {},
"RemoveInvalidTestSuiteLinks": false,
"FilterCompleted": false
}
],
"Version": "14.4",
"workaroundForQuerySOAPBugEnabled": false,
"WorkItemTypeDefinition": {
"sourceWorkItemTypeName": "targetWorkItemTypeName"
},
"Endpoints": {
"InMemoryWorkItemEndpoints": [
{
"Name": "Source",
"EndpointEnrichers": null
},
{
"Name": "Target",
"EndpointEnrichers": null
}
]
}
}   

排查方向

  • 测试计划/套件重复:源或目标项目中存在同名或ID冲突的测试计划/测试套件,迁移工具查询时返回多个匹配项
  • 测试配置/变量重复:源项目中存在重复的测试配置、测试变量,导致工具无法唯一识别
  • 字段映射冲突:MultiValueConditionalMapConfig规则匹配到多个目标字段,或WorkItemTypeName用通配符*触发多类型匹配冲突
  • 区域/迭代路径重复:源或目标项目的Area/Iteration路径存在重复节点,工具遍历时报错
  • 工具版本bug:当前配置版本14.4存在已知的重复项查询逻辑缺陷

解决方法

  1. 清理重复测试资产

    • 登录源TFS项目测试中心,检查测试计划、测试套件列表,删除重复或冗余项;若目标项目已有同名资产,修改名称或删除后重新迁移
    • 检查测试配置、测试变量,合并重复项,确保每个配置/变量唯一
  2. 调整字段映射规则

    • 将FieldMaps中的WorkItemTypeName从通配符*改为具体工作项类型(如"Test Case"),避免多类型匹配冲突
    • 检查targetFieldsAndValues,确保无重复字段定义
  3. 添加测试计划过滤规则

    • 在TestPlansAndSuitesMigrationConfig中配置TestPlanQueryBit,指定迁移范围,减少匹配结果数量,示例:
      "TestPlanQueryBit": "WHERE [System.Title] CONTAINS 'V1.0 测试计划'"
      
  4. 修复区域/迭代路径

    • 检查源和目标项目的Area、Iteration路径,删除重复节点;若需映射,在AreaMaps/IterationMaps中明确一对一映射关系
  5. 升级迁移工具版本

    • 将配置中的Version升级到最新稳定版,修复旧版本存在的重复项查询bug

修改后的配置示例(关键部分)

{
  // ... 其余配置保持不变
  "FieldMaps": [
    {
      "$type": "MultiValueConditionalMapConfig",
      "WorkItemTypeName": "Test Case",
      "sourceFieldsAndValues": { "System.State": "New" },
      "targetFieldsAndValues": { 
        "Microsoft.VSTS.Common.ActivatedDate": null, 
        "Microsoft.VSTS.Common.ActivatedBy": null, 
        "Microsoft.VSTS.Common.ClosedDate": null, 
        "Microsoft.VSTS.Common.ClosedBy": null
      }
    }
  ],
  "Processors": [
    // ... 其余处理器保持不变
    {
      "$type": "TestPlansAndSuitesMigrationConfig",
      "Enabled": true,
      "PrefixProjectToNodes": false,
      "OnlyElementsWithTag": null,
      "TestPlanQueryBit": "WHERE [System.Title] CONTAINS '待迁移测试计划'",
      "RemoveAllLinks": false,
      "MigrationDelay": 0,
      "UseCommonNodeStructureEnricherConfig": false,
      "NodeBasePaths": [],
      "AreaMaps": null,
      "IterationMaps": {},
      "RemoveInvalidTestSuiteLinks": false,
      "FilterCompleted": false
    }
  ]
}

内容的提问来源于stack exchange,提问作者Sijith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 15:35:04