Not able to add test cases to type of IRequirement

2019-07-31 05:22发布

I have created a test case workitem using TFS API.When i am trying to the test case to IStaticTestSuite it was successfull.

  if (firstMatchingSuite.TestSuiteType == TestSuiteType.StaticTestSuite)
           ((IStaticTestSuite)firstMatchingSuite).Entries.Add(testCase);

But i am not able to add a test case to IRequirementTestSuite using the below code.I get "Cannot add or remove test cases" error.

   if (firstMatchingSuite.TestSuiteType == TestSuiteType.RequirementTestSuite)
          ((IRequirementTestSuite)firstMatchingSuite).TestCases.Add(testCase);

Any suggestions ?

1条回答
贼婆χ
2楼-- · 2019-07-31 06:22

Yes.

The only way I found is via the TFS API as such (Using only what you wrote you have):

var store = ((IRequirementTestSuite)firstMatchingSuite).Project.WitProject.Store;
var tfsRequirement = store.GetWorkItem(((IRequirementTestSuite)firstMatchingSuite).RequirementId);

tfsRequirement.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Tested By"], testCase.WorkItem.Id));
tfsRequirement.Save();

((IRequirementTestSuite)firstMatchingSuite).Repopulate();

It works, I checked!

Enjoy :)

查看更多
登录 后发表回答