将测试用例以及步骤和数据从一个TFS迁移到另一个TFS [英] Migrate test case along with steps and data from one TFS to another
本文介绍了将测试用例以及步骤和数据从一个TFS迁移到另一个TFS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个Win App,我可以从一个TFS的一个项目中读取测试用例,然后转移到另一个TFS中的另一个项目。我能够实现相同但我想迁移测试步骤以及测试数据。
这就是我现在写的
在数据网格中显示测试用例
Hi,
I am trying to create a Win App where i can read test case from one project of one TFS and then move to another project in another TFS. I was able to implement the same but i want to migrate the test steps as well as the test data.
This is what i have written now
To show the test case in a datagrid
WorkItemStore workItemStore = new WorkItemStore(_TfsTeamProjectCollection);
queryResults = workItemStore.Query(
"Select [State], [Title] " +
"From WorkItems " +
"Where [Work Item Type] = 'Test Case' AND [Team Project]='" + _ProjectInfo.Name + "' " +
"Order By [ID] Asc ");
DataTable dtWorkItem = new DataTable();
dtWorkItem.Columns.Add("Title", typeof(string));
dtWorkItem.Columns.Add("State", typeof(string));
dtWorkItem.Columns.Add("Created By", typeof(string));
dtWorkItem.Columns.Add("Created On", typeof(string));
foreach (WorkItem workItem in queryResults)
{
dtWorkItem.Rows.Add(workItem.Title, workItem.State, workItem.CreatedBy, workItem.CreatedDate);
}
dsWorkitems.Tables.Add(dtWorkItem);
if (dsWorkitems != null)
{
testCaseGrid.DataSource = null;
testCaseGrid.DataSource = dsWorkitems.Tables[0];
}
然后将数据导入目标tfs项目
Then to Import data to the target tfs project
public void SaveWorkItem(WorkItemCollection workItemCollection)
{
try
{
int conflictCount = 0;
Project _Project;
WorkItemType _WorkItemType;
WorkItem _WorkItem = null;
WorkItemStore _WorkItemStore = new WorkItemStore(_TfsTeamProjectCollection);
foreach (WorkItem workItem in workItemCollection)
{
if (workItem.Id > 0)
{
_Project = _WorkItemStore.Projects[_ProjectInfo.Name];
_WorkItemType = _Project.WorkItemTypes["Test Case"];
_WorkItem = CheckWorkItemExist(_WorkItemStore, _WorkItemType, workItem.Title);
if (_WorkItem == null)
{
// Create the work item.
_WorkItem = new WorkItem(_WorkItemType)
{
// The title is generally the only required field that doesn’t have a default value.
// You must set it, or you can’t save the work item. If you’re working with another
// type of work item, there may be other fields that you’ll have to set.
Title = workItem.Title,
Description = workItem.Description
};
// Save the new user story.
//_WorkItem.Save();
}
else
{
conflictCount++;
objLog.LogEvent("Test Case already exists. Work Item ID: " + workItem.Id + ". Work Item Title:" + workItem.Title);
}
}
}
if (conflictCount == 0)
{
MessageBox.Show("All Work Items Imported Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
objLog.LogEvent("Imported Successfully!!!", "Information");
}
}
catch (Exception ex)
{
throw ex;
}
}
现在我想要迁移测试步骤和数据。任何人都可以帮助我
Now i want to migrate the test steps as well as data. Can anyone please help me
推荐答案
private void TestCaseActions()
{
var tfsColl = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(_TfsTeamProjectCollection.Uri);
var tcmService = tfsColl.GetService<itestmanagementservice>();
var testProject = tcmService.GetTeamProject(_ProjectInfo.Name);
var testCases = testProject.TestCases.Query("Select [State], [Title]From WorkItems Where [Work Item Type] = 'Test Case' " +
"AND [Team Project]='" + _ProjectInfo.Name + "' Order By [ID] Asc ");
// iterate each test case
foreach (ITestCase testCase in testCases)
{
}
}
</itestmanagementservice>
这解决了我的问题
This solved my issue
这篇关于将测试用例以及步骤和数据从一个TFS迁移到另一个TFS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文