Using the TFS API, how can I get the outcome/result of a specific test case in a given test suite and plan?
With outcome/result I mean the value that tests are grouped by in MTM: Passed, failed, active, in progress or blocked
Using the TFS API, how can I get the outcome/result of a specific test case in a given test suite and plan?
With outcome/result I mean the value that tests are grouped by in MTM: Passed, failed, active, in progress or blocked
This is how I do it.
To get passed and totalTests I use: ITestRun run*
run.PassedTests and run.TotalTests
To see run state I use:
TestRunSTate.Aborted and TestRunState.InProgress
To see if the failed or is inconclusive I use:
TestOutcome.Failed or TestOutcome.Inconclusive
First I only used ITestRun to easy se results, but I see they lack any kind of "failed" there which I find very disturbing. So to send the right numbers to my test report that is mailed to the product owner I do the following when talking to the tfs api:
var tfs = Connect(optionsModel.CollectionUri);
var tcm = GetService<ITestManagementService>(tfs);
var wis = GetService<WorkItemStore>(tfs);
_testProject = tcm.GetTeamProject(optionsModel.TeamProjectName);
var plan = _testProject.TestPlans.Find(optionsModel.PlanId);
if (plan == null)
throw new Exception("Could not find plan with that id.");
var run = plan.CreateTestRun(true);
var testSuite = _testProject.TestSuites.Find(optionsModel.SuiteId);
if (testSuite == null)
throw new Exception("Could not find suite with that id.");
AddTestCasesBySuite(testSuite, optionsModel.ConfigId, plan, run);
run.Title = optionsModel.Title;
run.Save();
var failedTests = run.QueryResultsByOutcome(TestOutcome.Failed).Count;
var inconclusiveTests = run.QueryResultsByOutcome(TestOutcome.Inconclusive).Count;
Hope this helps optionsmodel is the information I take in from the user running the tsts
I was trying to do the same thing, but using the REST API.
Just in case it helps someone, I managed to do that obtaining the testpoints from the suite:
https://dev.azure.com/{organization}/{project}/_apis/testplan/Plans/{planId}/Suites/{suiteId}/TestPoint?api-version=5.1-preview.2
You can use ITestManagementService
and TestPlan
query to get the result of specific Test plan
var server = new Uri("http://servername:8080/tfs/collectionname");
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(server);
var service = tfs.GetService<ITestManagementService>();
var testProject = service.GetTeamProject(teamProject);
var plans = testProject.TestPlans.Query("SELECT * FROM TestPlan").Where(tp => tp.Name == YOURTESTPLANNAME).FirstOrDefault();
ITestPlanCollection plans = tfsConnectedTeamProject.TestPlans.Query("Select * From TestPlan");
foreach (ITestPlan plan in plans)
{
if (plan.RootSuite != null && plan.RootSuite.Entries.Count > 0)
{
foreach (ITestSuiteEntry suiteEntry in plan.RootSuite.Entries)
{
var suite = suiteEntry.TestSuite as IStaticTestSuite;
if (suite != null)
{
ITestSuiteEntryCollection suiteentrys = suite.TestCases;
foreach (ITestSuiteEntry testcase in suiteentrys)
{
// Write code to get the test case
}
}
}
}
}
I hope this may help you.