簡體   English   中英

使用 TFS api 執行(通過/失敗)測試用例?

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

我目前正在開發一個程序以在程序中執行測試用例,並且我查看了如何使用 Team Foundation Server API 創建測試運行和結果? 以及其他各種文章,但仍然遇到很多麻煩。 我的目標是找到具有特定標題和配置的測試用例,執行它並在失敗時添加注釋。 這只是我一直在搞亂的一些代碼

        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); 那是我得到錯誤“nullreferenceexception is unhandled”的那一行,它是套件,但對象看起來很好。 如果你能幫忙,請告訴我:)

看起來您可能無法正確訪問 teamProject 以查看將其傳遞給計划所需的所有字段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM