简体   繁体   English

使用 TFS api 执行(通过/失败)测试用例?

[英]Using TFS api to execute(pass/fail) test cases?

I am currently working on a program to execute test cases in a program, and I have looked at How to create a test run and result using the Team Foundation Server API?我目前正在开发一个程序以在程序中执行测试用例,并且我查看了如何使用 Team Foundation Server API 创建测试运行和结果? as well as various other articles and am still having lots of trouble.以及其他各种文章,但仍然遇到很多麻烦。 My goal is to locate a test case with a certain title and configuration, execute it and add notes if it failed.我的目标是找到具有特定标题和配置的测试用例,执行它并在失败时添加注释。 Here is just some code I have been messing around with这只是我一直在搞乱的一些代码

        String server = "http://tfs.net:8080/tfs";
        String project = "Project";
        // Connect to the TeamFoundationServer.
        Console.Write("Connecting to Team Foundation Server {0}...\n", server);

        TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(server));
        Console.WriteLine("Success!\n");
        Console.WriteLine("getting project {0}...\n", project);

        ITestManagementTeamProject teamProject = projectCollection.GetService<ITestManagementService>().GetTeamProject(project);

        Console.WriteLine("Success!\nGetting test cases...\n\n");
        IEnumerable<ITestCase> testCases = teamProject.TestCases.Query("SELECT [Title] FROM WorkItems WHERE State = 'Ready' AND Title CONTAINS 'Phase 1: test case title'");
        foreach (ITestCase t in testCases)
            Console.WriteLine(t.Title);
        ITestSuiteCollection suites = teamProject.TestSuites.Query("SELECT * FROM TestSuite");



        ITestConfigurationCollection configs = teamProject.TestConfigurations.Query("Select * FROM TestConfiguration WHERE Name='Mainline Android Phone 2.3'");
        ITestConfiguration config = configs[0];

        ITestPlan plan = teamProject.TestPlans.Create();
        plan.Name = "herpa derp";

        ITestSuiteBase suite = teamProject.TestSuites.Find(606);


        Console.WriteLine(plan.Name);
        Console.WriteLine(suite.Title);
        plan.RootSuite.Entries.Add(suite);//Object reference not set to an instance of an object.
        plan.Save();

        suite.TestCases.AddCases(testCases);
        plan.Save();

        ITestRun run = plan.CreateTestRun(false);


        ITestPointCollection points = plan.QueryTestPoints("SELECT * FROM TestPoint");
        foreach (ITestPoint p in points)
        {
            run.AddTestPoint(p, null);
        }
        run.Save();
        ITestCaseResult result = run.QueryResults()[0];
        result.Outcome = TestOutcome.Passed;
        result.Save();

        //wait dood
        Console.Read();

plan.RootSuite.Entries.Add(suite); that is the line where I get the error "nullreferenceexception was unhandled" it's the suite, but the object looks fine.那是我得到错误“nullreferenceexception is unhandled”的那一行,它是套件,但对象看起来很好。 Please let me know if you can help :)如果你能帮忙,请告诉我:)

看起来您可能无法正确访问 teamProject 以查看将其传递给计划所需的所有字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用tfs API在tfs中通过测试用例 - Pass test case in tfs using tfs api 通过REST API将测试结果发布到TFS 2018测试用例 - Publishing test results to TFS 2018 test cases via REST API 如何通过TFS API检索测试计划中的所有测试用例? - How to retrieve all Test Cases in a Test Plan via TFS API? 测试用例在 Null 断言上失败 - Test Cases Fail On Null Assertion 在不使用AsNoTracking()的情况下执行查找/更新Xunit测试用例 - Execute Find/Update Xunit test cases without using AsNoTracking() 如何使用Microsoft Test Manager在多个系统中从TFS自动化多个测试用例? - How to automate multiple test cases from TFS in multiple systems using Microsoft Test Manager? C#TFS API将测试用例添加到基于需求的套件中 - C# TFS API add test cases to Requirement-based suite 在C#中将通用测试用例添加到TFS - Adding Generic Test Cases to TFS in C# 如何将自动化测试执行结果更新到 AzureDevOps/TFS 中的测试用例中 - How to update automation test execution results into the test cases in AzureDevOps/TFS 如何使用MTM将参数值从TFS中的测试用例传递到单元测试方法中的测试方法? - How to pass parameter values from test case in TFS to test method in unit test method using MTM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM