使用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$)
创建新测试。 此示例假定包含的主题文件夹 新测试直接位于根“Subject”文件夹下。
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: ""
End Sub
提前致谢!
答案 0 :(得分: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;
}
然后,通过使用返回的测试工厂,您可以在此文件夹中创建测试。
答案 1 :(得分: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;
}
}