Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未使用TFS API从TestSuite获取测试用例结果(通过/失败/阻止)_C#_Tfs_Microsoft Test Manager - Fatal编程技术网

C# 未使用TFS API从TestSuite获取测试用例结果(通过/失败/阻止)

C# 未使用TFS API从TestSuite获取测试用例结果(通过/失败/阻止),c#,tfs,microsoft-test-manager,C#,Tfs,Microsoft Test Manager,我正试图根据测试计划从TestSuite获得测试用例结果(通过/失败/阻止) 使用下面的代码来执行此操作 public List<ScoreBoard> GetTestStatistics(string teamProject, string selectedTestPlan) { // 1. Connect to TFS and Get Test Managemenet Service and Get all Test Plans str

我正试图根据测试计划从TestSuite获得测试用例结果(通过/失败/阻止)

使用下面的代码来执行此操作

  public List<ScoreBoard> GetTestStatistics(string teamProject, string selectedTestPlan)
    {
        // 1. Connect to TFS and Get Test Managemenet Service and Get all Test Plans
        string serverName = "*********";
        var server = new Uri(serverName);
        var tfs = TfsTeamProjectCollectionFactory
        .GetTeamProjectCollection(server);
        var service = tfs.GetService<ITestManagementService>();
        var testProject = service.GetTeamProject(teamProject);
        var plan = testProject.TestPlans.Query("SELECT * FROM TestPlan").Where(tp => tp.Name == selectedTestPlan).FirstOrDefault();
        List<ScoreBoard> scoreboards = new List<ScoreBoard>();
        var testSuits = new List<IStaticTestSuite>();
        if (plan.RootSuite != null)
        {
            testSuits.AddRange(TestSuiteHelper.GetTestSuiteRecursive(plan.RootSuite));
        }
        TestPlan testPlan = new TestPlan() { Id = plan.Id, Name = plan.Name, TestSuites = testSuits };

        for (int i = 0; i < testPlan.TestSuites.Count; i++)
        {
            var ts = testPlan.TestSuites[i];
            var scoreboard = new ScoreBoard();
            scoreboard.TeamProject = teamProject;
            scoreboard.TestPlan = selectedTestPlan;
            scoreboard.Id = ts.Id;
            scoreboard.Title = ts.Title;
            scoreboard.State = ts.State.ToString();
            scoreboard.TestCaseCount = ts.TestCases.Count;

              int totalTestSteps = 0;
            List<string> testStepScores = new List<string>();
            foreach (var tc in ts.TestCases)
            {
                foreach (var a in tc.TestCase.Actions)
                {
                    totalTestSteps = totalTestSteps + 1;
                }                

                var testResults = testProject.TestResults.ByTestId(tc.TestCase.TestSuiteEntry.Id);
                foreach (var result in testResults)
                {


                    for (int actionIndex = 0; actionIndex < tc.TestCase.Actions.Count; actionIndex++)
                    {
                        var action = tc.TestCase.Actions[actionIndex];
                        if (!(action is ITestStep))
                        {
                            continue;
                        }
                        var step = action as ITestStep;
                        var topIteration = result.Iterations.FirstOrDefault();
                        if (topIteration == null)
                            continue;

                        var test = topIteration.Actions[actionIndex];
                        testStepScores.Add(topIteration.Actions[actionIndex].Outcome.ToString());
                    }
                }
            }
              scoreboard.TestStepCount = totalTestSteps;
            scoreboard.TestStepPassedCount = testStepScores.Where(tsp => tsp == "Passed").ToList().Count;
            scoreboard.TestStepFailedCount = testStepScores.Where(tsp => tsp == "Failed").ToList().Count;
            scoreboard.TestStepOutstandingCount = testStepScores.Where(tsp => tsp == "None").ToList().Count;
            scoreboards.Add(scoreboard);
        }
        return scoreboards;
    }
公共列表GetTestStatistics(字符串teamProject,字符串selectedTestPlan)
{
//1.连接到TFS并获取测试管理网服务并获取所有测试计划
字符串serverName=“**********”;
var server=新的Uri(serverName);
var tfs=tfstreamprojectcollectionfactory
.GetTeamProjectCollection(服务器);
var service=tfs.GetService();
var testProject=service.GetTeamProject(teamProject);
var plan=testProject.TestPlans.Query(“从TestPlan中选择*)。其中(tp=>tp.Name==selectedTestPlan)。FirstOrDefault();
列表记分牌=新列表();
var testSuits=新列表();
if(plan.RootSuite!=null)
{
testsuitehelp.getTestSuiterCursive(plan.RootSuite));
}
TestPlan TestPlan=newtestplan(){Id=plan.Id,Name=plan.Name,TestSuites=TestSuites};
for(int i=0;itsp==“通过”).ToList().Count;
scoreboard.TestStepFailedCount=testStepScores.Where(tsp=>tsp==“失败”).ToList().Count;
scoreboard.TestStepOutstandingCount=testStepScores.Where(tsp=>tsp==“无”).ToList().Count;
记分牌。添加(记分牌);
}
返回记分牌;
}
我没有得到通过测试/失败/未完成测试计数的正确结果。 当我对此进行调试时,观察到一些属性显示消息“函数求值已禁用,因为以前的函数求值超时。必须继续执行才能重新启用函数求值。” 我可以得到多少测试用例通过了测试套件吗?
这里可能有什么问题?

求值消息意味着对象需要很长时间才能返回属性值,一旦发生这种情况,您将丢失对象信息,直到允许执行继续。因为TFSAPI支持延迟执行,所以从服务器查询结果很可能需要很长时间。尝试写入跟踪或将结果输出到控制台窗口,通过调用ToList()等强制执行记录集。