c# - How to get unit test results using TFS Rest API? -
how retrieve unit test results of build in tfs using rest api?
the build definition uses vnext (visual studio 2015 update 3).
var vssconnection = new vssconnection(_configurationspec.teamprojectcollection, new vssclientcredentials()); _buildclient = vssconnection.getclient<buildhttpclient>();
the test result of build stored in test runs, need test run of build first , retrieve test result test run. following code sample:
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 = 1; build bui = bhc.getbuildasync(projectname,buildid).result; //get test run build testmanagementhttpclient ithc = ttpc.getclient<testmanagementhttpclient>(); console.writeline(bui.buildnumber); querymodel qm = new querymodel("select * testrun 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.testcase.name); console.writeline(tcr.outcome); } console.readline(); } console.readline(); } }
Comments
Post a Comment