之前在HP的时候用ALM,还是很好用的功能很强大的一个测试管理工具,当时用C#依照ALM的API实现了一个上传测试结果的程序,现在贴出来:
这个程序的使用方式很*,使得ALM几乎可以和所有测试工具做集成,只要测试工具能够提供xml的测试结果
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; using TDAPIOLELib; namespace ALMConnector
{
public class ALMConnection
{
private TDConnection almConnection;
private TestSetTreeManager tsTreeMan;
private TestSetFolder rootFolder;
// 初始化建立到ALM的connection
public ALMConnection(string almURL_)
{
almConnection = new TDConnection();
almConnection.InitConnectionEx(almURL_);
} ~ALMConnection()
{
// Extremely important to clean up and release resoures when done
DisconnectProject();
Logout();
almConnection.ReleaseConnection();
} public string ServerULR
{
get
{
return almConnection.ServerURL;
}
} public string UserName
{
get
{
return almConnection.UserName;
}
} public string DomainName
{
get
{
return almConnection.DomainName;
}
} public string ProjectName
{
get
{
return almConnection.ProjectName;
}
} public TDAPIOLELib.List ProjectList
{
get
{
return almConnection.ProjectsList;
}
}
//用户名密码登陆
public void Login(string userName_, string password_)
{
almConnection.Login(userName_, password_);
}
//连接到项目,得到项目的testsuite rootfolder
public void ConnectProject(string domainName_, string projectName_)
{
if (almConnection.Connected)
{
almConnection.Connect(domainName_, projectName_);
GetRootFolder();
}
}
//释放connection
public void DisconnectProject()
{
if (almConnection.Connected)
{
almConnection.Disconnect();
}
}
//登出
public void Logout()
{
if (almConnection.LoggedIn)
{
almConnection.Logout();
}
}
//获取到testset的folder
public bool FindTestSetFolder(string almFolderPath, out TestSetFolder almFolder)
{
almFolder = (TestSetFolder)tsTreeMan.get_NodeByPath(almFolderPath);
return !(almFolderPath == null);
} public TestSetFolder GetRootFolder()
{
if (tsTreeMan == null)
{
tsTreeMan = (TestSetTreeManager)almConnection.TestSetTreeManager;
}
if (rootFolder == null)
{
rootFolder = (TestSetFolder)tsTreeMan.Root;
}
return rootFolder;
}
//建立testset
public bool CreateTestSet(TestSetFolder targetFolder_, string newTestSetName_, out TestSet testSetInstance_)
{
List tsList = targetFolder_.FindTestSets(newTestSetName_);
if (tsList == null)
{
TestSetFactory tsFact = targetFolder_.TestSetFactory;
TestSet tsNew = tsFact.AddItem(DBNull.Value);
tsNew.Name = newTestSetName_;
tsNew.Status = "Open";
tsNew.Post(); testSetInstance_ = tsNew; return true;
}
else if (tsList.Count == )
{
testSetInstance_ = tsList[];
}
else
{
testSetInstance_ = null;
} return false;
}
//上传测试结果到testset
public bool AddTestResultToTestSet(TestSet tsRun, TestResult tsResult)
{
TSTestFactory tsTestFact = tsRun.TSTestFactory;
TSTest newTSTest = tsTestFact.AddItem(tsResult.TestId);
newTSTest.Status = tsResult.TestStatus;
newTSTest.Post(); return true;
}
//上传attachment到testset
public void UploadAttachmentToTestSet(TestSet tsRun, String reportPath)
{
TestSet tSet = null;
AttachmentFactory attfat = null;
Attachment attobj = null;
if (File.Exists(reportPath))
{
Console.WriteLine("Find Attachment File,Uploading ...");
tSet = tsRun;
attfat = tSet.Attachments;
attobj = attfat.AddItem(System.DBNull.Value);
attobj.FileName = reportPath;
attobj.Type = ;
attobj.Post();
}
}
}
}