2017-12-04 7 views
3

私はプログラム的にこれらを追加したいと思いVSTSでのビルド中にテスト結果に添付ファイルをプログラムで追加するにはどうすればよいですか?

enter image description here

....ビルドがここに完了した後、私はそれらを見ることができるように、結果をテストするために自分自身の添付ファイルを追加する方法を探していますビルド中およびテストが失敗した後。添付ファイルはスクリーンショットになります。

これは可能ですか?

私はAPIリファレンスを簡単に見ていましたが、これは既存のテスト '実行'に添付ファイルを追加することに関係していたか、ビルド側ではビルド定義を作成してトリガーすることでした。私はそれを見逃しているかもしれませんが、テストタスクが完了した直後または直後にコードから添付ファイルを追加する方法を見つけることができませんでした。

おかげで、

+0

あなたはSpecflow&セレンでテストを書きましたか? –

答えて

0

You could get test run of the build first and then retrieve the test result from the test run

class Program 
{ 
    static void Main(string[] args) 
    { 
     string ur = "https://xxxxxxx/"; 
     TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(ur)); 
     //Get build information 
     BuildHttpClient bhc = ttpc.GetClient<BuildHttpClient>(); 
     string projectname = "Project"; 
     int buildId = x; 
     Build bui = bhc.GetBuildAsync(projectname,buildId).Result; 
     //Get test run for the build 
     TestManagementHttpClient ithc = ttpc.GetClient<TestManagementHttpClient>(); 

     Console.WriteLine(bui.BuildNumber); 

     QueryModel qm = new QueryModel("Select * From TestRun Where BuildNumber Contains '" + bui.BuildNumber + "'"); 

     List<TestRun> testruns = ithc.GetTestRunsByQueryAsync(qm,projectname).Result; 
     foreach (TestRun testrun in testruns) 
     { 

      List<TestCaseResult> testresults = ithc.GetTestResultsAsync(projectname, testrun.Id).Result; 
      foreach (TestCaseResult tcr in testresults) 
       { 
        Console.WriteLine(tcr.Id); 
        Console.WriteLine(tcr.Outcome); 
       } 

      Console.ReadLine(); 
     } 
     Console.ReadLine(); 
    } 
} 

あなたが失敗したテスト結果IDを取得したら、あなたはRest API to attach a file to test resultを使用することができます。

POST https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results/{result}/attachments?api-version={version} 
Content-Type: application/json 
{ 
    "stream": { string }, 
    "fileName": { string }, 
    "comment": { string }, 
    "attachmentType": { string } 
} 
関連する問題