2016-07-29 3 views
1

TFS/MTM에서 테스트 케이스를 전달하는 코드는 다음과 같습니다. 테스트 케이스를 외부에서 전달하려고했지만 테스트 케이스의 내부 단계를 확인하면됩니다. 테스트 케이스의 각 액션을 통과시켜 테스트 케이스를 전달하려고합니다. 도움을 청하니 .tfs api를 사용하여 tfs의 테스트 케이스 전달

ITestPlan tp = testinsuitesd.Plan; 
// foreach (ITestCase testcase in allTestCases) 
//{ 

ITestRun testRun = testinsuitesd.Plan.CreateTestRun(false); 
ITestPointCollection testPoints = tp.QueryTestPoints("select * from TestPoint where suiteId= "+ testinsuitesd.Id); 
    foreach(ITestPoint testRuns in testPoints) 
    { 
     testRun.AddTestPoint(testRuns, null); 
    } 
    testRun.Save(); 

    ITestCaseResultCollection testCaseResult = testRun.QueryResults();  //code to Pass the test Case 
    foreach (ITestCaseResult testResult in testCaseResult) 
     { 
    ITestIterationResult iterationResult; 
    ITestActionResult actionResults;         
     iterationResult = testResult.CreateIteration(1); 
    //actionResults = testResult.CreateIteration(1); 
      foreach (ITestAction testStep in testResult.GetTestCase().Actions) 
      { 

       ITestActionResult stepResult = iterationResult.CreateStepResult(testStep.Id);              
       //stepResult.ErrorMessage = String.Empty;            
       stepResult.Outcome = TestOutcome.Passed; //you can assign different states here 

       iterationResult.Actions.Add(stepResult); 
     //actionResults.Add(stepResult); 
      // iterationResult.Actions.Add(stepResult); 
     // actionResults. Add(stepResult); 
      } 

      iterationResult.Outcome = TestOutcome.Passed;           
      testResult.Iterations.Add(iterationResult); 
    testResult.Outcome = TestOutcome.Passed; 
    testResult.State = TestResultState.Completed; 
    testResult.Save(); 
     } 
    testCaseResult.Save(false); 
// testCaseResult. 
    testRun.Save(); 
    testRun.Refresh(); 

tp.Save(); 

답변

-1

아래 코드로 시도 :

  • Code snippets on Test Management APIs
  • Test case result using TFS API
  • MTM Testing Scorecard using TFS API
  • :

    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); 
    

    또한, 당신이 도움이 될 수 TFS API에 대한 몇 가지 링크도 있습니다,363,210

  • How to create a test run and result using the Team Foundation Server API?
+1

안녕 "_testEditInfo"위의 사용 목적은 당신이 알려 주시기 바랍니다 수 있습니까? 타입이다 뭐죠 내 코드의 문제. –

관련 문제