2012-08-10 156 views
0

使用QC集成工具並且無法在測試計劃中創建測試 - 不幸的是API是爲VB6編寫的,而且我正在使用C#。HPQC C#創建測試計劃測試

這裏是我到目前爲止有:

private void HPQC_Create_Test_Plan_Test(TDConnectionClass tdConnection, string ParentFolderPath, string TestName) 
    { 
     try 
     { 
      TreeManager treeM = (TreeManager)tdConnection.TreeManager; 
      ISysTreeNode ParentFolder = (ISysTreeNode)treeM.get_NodeByPath(ParentFolderPath); 
      TestFactory TestF = (TestFactory)tdConnection.TestFactory; 

      Test TstTest = (Test)TestF.AddItem(System.DBNull.Value); 
      TstTest.Name = TestName; 
      TstTest.Type = "MANUAL"; 
      TstTest.Post(); 

      HPQC_Status_Test_Plan.Text = "Test " + TestName + " created."; 

      tdConnection.Logout(); 
      tdConnection.Disconnect(); 
      tdConnection = null; 

     } 
     catch (Exception ex) 
     { 
      HPQC_Status_Test_Plan.Text = "Test Creation Failed."; 
      Console.WriteLine("[Error] " + ex); 

      tdConnection.Logout(); 
      tdConnection.Disconnect(); 
      tdConnection = null; 

     } 
    } 

的代碼錯誤出在後用一個簡單的「無法郵報」,我不知所措,爲什麼。

下面是VB6的API例如:

Public Sub AddTest(FolderName$, TestName$) 

創建新的考驗。 本示例假定包含 新測試的主題文件夾直接位於根目錄「主題」文件夾下。

Dim objTest As Test 
Dim folder As SubjectNode 
Dim testF As TestFactory 
Dim TreeMgr As TreeManager 
Dim Path As String 

Dim Trees As List 
Dim RootName As String 
Dim SubjRoot As SubjectNode 

'tdc is the global TDConnection object. 
Set TreeMgr = tdc.TreeManager 

' Use TreeManager.TreeRoot to get the list of subject 
' root nodes from the tree manager. 
' There is only one item in this list. 
Set Trees = TreeMgr.RootList(TDOLE_SUBJECT) 

' Get the name of the subject tree root in your project. 
RootName = Trees.Item(1) 

Path = RootName & "\" & FolderName 

On Error Resume Next 
Set folder = TreeMgr.NodeByPath(Path) 
On Error GoTo 0 

If folder Is Nothing Then 'Create the folder 
    ' Get the SubjectNode root node object from the 
    ' tree manager by name. 
    Set SubjRoot = TreeMgr.TreeRoot(RootName) 
    Set folder = SubjRoot.AddNode(FolderName) 
End If 

Set testF = folder.TestFactory 
Set objTest = testF.AddItem(Null) 
objTest.name = TestName 
objTest.Type = "SYSTEM-TEST" 
objTest.Post 

Dim VerCtl As VCS 
Dim bIsLocked As Boolean 
Dim strLockedBy As String 

Set VerCtl = objTest.VCS 

VerCtl.Refresh 

bIsLocked = VerCtl.IsLocked 
strLockedBy = VerCtl.LockedBy 

' After POST, Test is checked in. 
Debug.Print "Is locked: " & bIsLocked 
'Is locked: False 
Debug.Print "Is locked by: """ & strLockedBy & """" 
'Is locked by: "" 

VerCtl.CheckOut -1, "To change state", True 

VerCtl.Refresh 

bIsLocked = VerCtl.IsLocked 
strLockedBy = VerCtl.LockedBy 

Debug.Print "Is locked: " & bIsLocked 
'Is locked: True 
Debug.Print "Is locked by: """ & strLockedBy & """" 
'Is locked by: "User1" 

' Take an arbitrary field to change. 
Debug.Print "Status: """ & objTest.Field("TS_STATUS") & """" 
'Status: "" 

objTest.Field("TS_STATUS") = "Ready" 

objTest.Post 

VerCtl.CheckIn "", "Changed status" 

VerCtl.Refresh 

bIsLocked = VerCtl.IsLocked 
strLockedBy = VerCtl.LockedBy 

Debug.Print "Is locked: " & bIsLocked 
'Is locked: False 
Debug.Print "Is locked by: """ & strLockedBy & """" 
'Is locked by: "" 

末次

提前感謝!

回答

0

給了週末思考一下,並意識到上面的代碼沒有父樹屬性鏈接到樹中。不幸的是,C#中的TreeManager由於某種原因沒有TreeRoot。

通過爲原型手動抓取路徑解決了這個問題 - 用戶必須在父路徑中鍵入「Root \ Subject」到文本框中。

關鍵屬性是「TS_Subject」,它是要附加測試的文件夾的NodeID。

下面的代碼對我的作品:

private void HPQC_Create_Test_Plan_Test(TDConnectionClass tdConnection, string ParentFolderPath, string TestName) 
    { 
     try 
     { 
      TreeManager treeM = (TreeManager)tdConnection.TreeManager; 
      ISysTreeNode ParentFolder = (ISysTreeNode)treeM.get_NodeByPath(ParentFolderPath); 
      TestFactory TestF = (TestFactory)tdConnection.TestFactory; 

      Test TstTest = (Test)TestF.AddItem(System.DBNull.Value); 
      TstTest.Name = TestName; 
      TstTest.Type = "MANUAL"; 
      TstTest["TS_SUBJECT"] = ParentFolder.NodeID; 
      TstTest.Post(); 

      HPQC_Status_Test_Plan.Text = "Test " + TestName + " created."; 

      tdConnection.Logout(); 
      tdConnection.Disconnect(); 
      tdConnection = null; 

     } 
     catch (Exception ex) 
     { 
      HPQC_Status_Test_Plan.Text = "Test Creation Failed."; 
      Console.WriteLine("[Error] " + ex); 

      tdConnection.Logout(); 
      tdConnection.Disconnect(); 
      tdConnection = null; 

     } 
    } 
1

我有類似,但更適合生成一個文件夾結構也是東西。 我們在QC中的根文件夾是「主題」,但您可以簡單地更改它以創建所需的特定文件夾。此外,不需要設置[「TS_SUBJECT」]標題,因爲我們正在使用葉節點上的節點將測試創建到指定文件夾中,所以這不是必需的。

private TestFactory addSubjectTreeStructure(String subjectField) 
    { 
     String folderRootString = subjectField; 
     folderRootString = folderRootString.Replace("\\", "/"); 
     String[] folders = folderRootString.Split('/'); 

     // Test Plan Tree Manager 
     TreeManager treeMgr = tdc.TreeManager; 
     SubjectNode subjectNode = treeMgr.get_NodeByPath("Subject"); 

     ISysTreeNode node = (ISysTreeNode)subjectNode; 

     // Creating the folders in test plan. 
     for (int i = 0; i < folders.Length; i++) 
     { 
      try 
      { 
       node = node.FindChildNode(folders[i]); 
      } 
      catch (Exception ex) 
      { 
       node = node.AddNode(folders[i]); 
       Console.WriteLine(ex.Message + ".\nChild not found. Adding new node: " + folders[i]); 
      } 
     } 

     // Set the leaf folder and then returning the TestFactory from where all test cases will be generated from. 
     SubjectNode folder = treeMgr.get_NodeById(node.NodeID); 
     return folder.TestFactory; 
    } 

然後通過使用返回的測試工廠,您可以在此文件夾中創建測試。