0

使用 QC 集成工具并在测试计划中创建测试时遇到问题 - 不幸的是,API 是为 VB6 编写的,而我正在使用 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: ""

结束子

提前致谢!

4

2 回答 2

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;
    }

然后通过使用返回的测试工厂,您可以在此文件夹中创建测试。

于 2013-05-14T14:56:15.737 回答
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;

        }
    }
于 2012-08-14T15:03:57.000 回答