C# 4.0 使用c创建类型测试用例的Tfs工作项#

C# 4.0 使用c创建类型测试用例的Tfs工作项#,c#-4.0,tfs,tfs-sdk,C# 4.0,Tfs,Tfs Sdk,我试图在VisualStudio中使用c#在TFS中创建一个类型测试用例的工作项。我可以设置除“步骤”字段之外的所有字段的值。如何设置步长字段的值 我尝试了workitem.Fields[“steps”].value=“value”,但不起作用。这不起作用,因为您必须使用对TestManagement客户端的引用。然后获取测试用例并添加如下新步骤: TfsTeamProjectCollection tfs; tfs = TfsTeamProjectCollectionFactory.GetTe

我试图在VisualStudio中使用c#在TFS中创建一个类型测试用例的工作项。我可以设置除“步骤”字段之外的所有字段的值。如何设置步长字段的值


我尝试了
workitem.Fields[“steps”].value=“value”
,但不起作用。

这不起作用,因为您必须使用对TestManagement客户端的引用。然后获取测试用例并添加如下新步骤:

TfsTeamProjectCollection tfs;

tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(uri)); 
tfs.Authenticate();

ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject testProject = service.GetTeamProject(project);    

ITestCase testCase = TestProject.TestCases.Find(1);
ITestStep newStep = testCase.CreateTestStep();
newStep.Title = "New Step Title";
newStep.ExpectedResult = "New Step Expected Result";
testCase.Actions.Add(newStep);
请查看以下链接:


  • 请注意
    Steps
    字段是
    html
    类型。您可以尝试使用RESTAPI来设置步骤的值。一个例子如下:

    POST https://xxxx.visualstudio.com/{teamproject}/_apis/wit/workitems/$Test%20Case?api-version=4.1
    
    Content-Type: application/json-patch+json
    
    [
      {
        "op": "add",
        "path": "/fields/System.Title",
        "from": null,
        "value": "Sample testcase"
      },
      {
        "op": "add",
        "path": "/fields/Microsoft.VSTS.TCM.Steps",
        "from": null,
        "value": "<steps id=\"0\" last=\"3\"><step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;step1&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;0&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><description/></step><step id=\"3\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;step2&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;P&gt;&amp;nbsp;pass&lt;/P&gt;</parameterizedString><description/></step></steps>"
      }
    ]
    
    POSThttps://xxxx.visualstudio.com/{teamproject}/_api/wit/workitems/$Test%20Case?api版本=4.1
    内容类型:应用程序/json修补程序+json
    [
    {
    “op”:“添加”,
    “路径”:“/字段/System.Title”,
    “from”:空,
    “值”:“示例测试用例”
    },
    {
    “op”:“添加”,
    “路径”:“/fields/Microsoft.VSTS.TCM.Steps”,
    “from”:空,
    “值”:“divpstep1 ;/P/DIV/DIVP ;0/P/divpstep2 ;/P/DIVP ;通过/P”
    }
    ]
    
    您使用的是哪个版本的TFS?您是如何指定“值”的?