簡體   English   中英

如何使用c#更改MTM中測試用例的自動化狀態?

[英]How to change Automation Status of test case in MTM using c#?

我們正在嘗試將UFT腳本與MTM集成。 到目前為止,我們已經成功做到了。 我們創建了許多使用TFS API的應用程序,對此我們感到滿意。

問題:我們如何更改測試用例的自動化狀態

我們做了什么:

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("Your URL"));
ITestManagementTeamProject project = tfs.GetService<ITestManagementService>().GetTeamProject("Ypur Project Name");
ITestPlan testPlan = project.TestPlans.find("Your test plan ID");
ItestCaseCollection testcasecollection = testPlan.RootSuite.AllTestCases;

foreach (ITestCase testcase in testcasecollection)
{
   if (testcase.Id=="YourTestcaseID")
   {
       //Now here we need tochange status of test case from Not Automated to automated 
       //we can change area path, title ,priority etc using TFS provided methods, but we cant change Automation status from Not Automated to others
       testcase.status="Active"; // to change status of test case from closed to active.

      // What is the method to change Automation status for a test case?? we only find method to get the automation status by using below method which is read only and returns value.
      string str=testcase.IsAutomated(); // this returns but not sets
   }
}

簡而言之,我們是否有像改變狀態和其他方法一樣使用C#更改MTM / TFS中測試用例的自動化狀態的方法?

使用以下方法:

    /// <summary>
    /// Associates an automation to the test case.
    /// </summary>
    /// <param name="testCase">The test case artifact to which to associate automation</param>
    /// <param name="automationTestName">The automation test name. It should be fully
    /// qualified of format "Namespace.ClassName.TestMethodName.</param>
    /// <param name="automationTestType">The automation test type like "CodedUITest".</param>
    /// <param name="automationStorageName">The assembly name containing the above
    /// test method without path like MyTestProject.dll.</param>
    private static ITestCase AssociateAutomation(ITestCase testCase,
        string automationTestName, string automationTestType, string automationStorageName)
    {
        // Build automation guid
        SHA1CryptoServiceProvider crypto = new SHA1CryptoServiceProvider();
        byte[] bytes = new byte[16];
        Array.Copy(crypto.ComputeHash(Encoding.Unicode.GetBytes(automationTestName)), bytes, bytes.Length);
        Guid automationGuid = new Guid(bytes);

        // Create the associated automation.
        testCase.Implementation = testCase.Project.CreateTmiTestImplementation(
                automationTestName, automationTestType,
                automationStorageName, automationGuid);

        // Save the test. If you are doing this for lots of test, you can consider
        // bulk saving too (outside of this method) for performance reason.
        return testCase;
    }

暫無
暫無

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

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