I'm trying to create programmatically a Test Plan, with a Test Suite and a Test Case. The problem is to add Test Steps to my Test Case. This code create correctly a Test Plan with a Test Suite and a Test Case but not Test Steps in my Test Case. Where am I wrong?
static void Main(string[] args)
{
try
{
var tfs = TfsHelper.TryToAutenticated();
var wis = tfs.GetService<WorkItemStore>();
//TEST PLAN
// Let's create a new Test Plan from scratch
// Only the Name property is required to be set before
// you can save, but we'll set a few extras here as well.
ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject myTestManagementTeamProject = service.GetTeamProject("GammaEnterprise");
ITestPlan newTestPlan = myTestManagementTeamProject.TestPlans.Create();
newTestPlan.Name = "My Test Plan";
newTestPlan.Save();
//TEST SUITE
// Next let's add a new Test Suite to our plan
// First, create a static suite (I'll cover Dynamic Suites
// in a future post)
IStaticTestSuite newSuite = myTestManagementTeamProject.TestSuites.CreateStatic();
newSuite.Title = "My Suite";
newTestPlan.RootSuite.Entries.Add(newSuite);
newTestPlan.Save();
//TEST CASE
// Let's find the default configuration that was created when
// we created our Team Project. We'll need this to add some
// tests to our new suite (or we could create a new one, but
// I'll keep things simple and just get the default one for now)
ITestConfiguration defaultConfig = null;
foreach (ITestConfiguration config in myTestManagementTeamProject.TestConfigurations.Query(
"Select * from TestConfiguration"))
{
defaultConfig = config;
break;
}
// I would typically check that defaultConfig is not null here
// but for brevity sake will skip that.
// Next we'll create a Testcase to add to our Test Suite
ITestCase tc = myTestManagementTeamProject.TestCases.Create();
tc.Title = "Verify X";
//HERE THE PROBLEM----------------------
ITestStep ts = tc.CreateTestStep();
ts.TestStepType = TestStepType.ActionStep;
ts.Description = "Description";
ts.Title = "Title";
//---------------------------------------
tc.Save();
// Now let's add it to your suite, we still have our reference
// to the static suite around so we'll use that
// First we need an "IdAndName" object for our config
IdAndName defaultConfigIdAndName = new IdAndName(defaultConfig.Id, defaultConfig.Name);
// Now we'll set the default configs for our suite
newSuite.SetDefaultConfigurations(new IdAndName[] { defaultConfigIdAndName } );
// Now let's add that testcase
newSuite.Entries.Add(tc);
// Now let's save the plan (don't need to explicitly
// save test suites).
newTestPlan.Save();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
You can use Namespace : Microsoft.TeamFoundation.TestManagement.Client
For example:
var step = testCase.CreateTestStep();
step.Title = "Step 1 @param1";
step.ExpectedResult = "Expect 1 @param2";
testCase.Actions.Add(step);
testCase.Save();
So I think you just need to add step to Actions.
More details:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.