0

我正在尝试使用 C# 代码来创建 TFS 测试运行。但每次我都低于错误。虽然我已经给出了测试计划的细节。我什至找不到这方面的文件。

错误

mscorlib.dll 中出现“Microsoft.TeamFoundation.TestManagement.WebApi.TestObjectNotFoundException”类型的异常,但未在用户代码中处理

附加信息:未找到测试计划 {0}。

代码

    public async Task CreateTestRun()
    {
        TestManagementHttpClient witClient = connection.GetClient<TestManagementHttpClient>();
        TestCaseResultUpdateModel TestCaseResultUpdateModel = new TestCaseResultUpdateModel();
        ShallowReference testPlanReference = new ShallowReference();
        testPlanReference.Id = "{TestPlanId}";
        testPlanReference.Name = "{TestPlanName}";
        testPlanReference.Url = "http://{TFSInstance}/{Project}/_apis/test/plans/{TestPlanID}";
        RunCreateModel RunCreateModel = new RunCreateModel("SWAT-Run","",new int[] {2304187},testPlanReference,
                                                            null,0,"",false,"Error Message","","","","","comment","","", "",
                                                            null, null, null, null,null,"","","","",new TimeSpan(0,0,10,0,0),"",null);
        TestRun testRun = await witClient.CreateTestRunAsync(this.Project, RunCreateModel, null);
    }
4

1 回答 1

0

我已经用下面的代码成功地完成了它,希望它对你有所帮助。

    var tfsRun = _testPoint.Plan.CreateTestRun(false);   
    tfsRun.DateStarted = DateTime.Now;
    tfsRun.AddTestPoint(_testPoint, _currentIdentity);
    tfsRun.DateCompleted = DateTime.Now;
    tfsRun.Save(); // so results object is created

    var result = tfsRun.QueryResults()[0];
    result.Owner = _currentIdentity;
    result.RunBy = _currentIdentity;
    result.State = TestResultState.Completed;
    result.DateStarted = DateTime.Now;
    result.Duration = new TimeSpan(0L);
    result.DateCompleted = DateTime.Now.AddMinutes(0.0);

    var iteration = result.CreateIteration(1);
    iteration.DateStarted = DateTime.Now;
    iteration.DateCompleted = DateTime.Now;
    iteration.Duration = new TimeSpan(0L);
    iteration.Comment = "Run from TFS Test Steps Editor by " + _currentIdentity.DisplayName;

    for (int actionIndex = 0; actionIndex < _testEditInfo.TestCase.Actions.Count; actionIndex++)
    {
        var testAction = _testEditInfo.TestCase.Actions[actionIndex];
        if (testAction is ISharedStepReference)
            continue;

        var userStep = _testEditInfo.SimpleSteps[actionIndex];

        var stepResult = iteration.CreateStepResult(testAction.Id);
        stepResult.ErrorMessage = String.Empty;
        stepResult.Outcome = userStep.Outcome;

        foreach (var attachmentPath in userStep.AttachmentPaths)
        {
            var attachment = stepResult.CreateAttachment(attachmentPath);
            stepResult.Attachments.Add(attachment);
        }

        iteration.Actions.Add(stepResult);
    }

    var overallOutcome = _testEditInfo.SimpleSteps.Any(s => s.Outcome != TestOutcome.Passed)
        ? TestOutcome.Failed
        : TestOutcome.Passed;

    iteration.Outcome = overallOutcome;

    result.Iterations.Add(iteration);

    result.Outcome = overallOutcome;
    result.Save(false);
于 2016-05-28T12:48:46.737 回答