Adding test cases

The following example describes how to add a test case.

1. Localize external namespaces.

using System;

using System.Collections.Generic;

using System.Text;

2. Set up the namespace, provide the login information, and define the project name.

namespace CreateTestCase

{

class CreateTestCase

{

static void Main (string[] args)

{

long cookie = -1;

ttsoapcgi ttsdk = null;

 

try

{

string username = "username";

string password = "password";

string ProjectName = "ProjectName";

3. Create an instance of the ttsoapcgi class, which is generated from the ttsoapcgi.wsdl file.

ttsdk = new ttsoapcgi();

4. Set the URL that the ttsdk object connects to if you are not using the default URL from the WSDL file.

ttsdk.Url = "http://localhost:80/scripts/ttsoapcgi.exe";

5. Select the Helix ALM project to connect to and set proj to reference it.

CProject[] projects = ttsdk.getProjectList(username, password);

CProject proj = null;

 

foreach (CProject p in projects)

{

if (p.database.name.Equals(projectName))

{

proj = p;

break;

}

}

6. Log in to the project.

cookie = ttsdk.ProjectLogon(proj, username, password);

7. Create a CTestCase object and enter the test case information.

You must provide data for all required fields to correctly initialize the object.

CTestCase TC = new CTestCase();

TC.summary = "Example Test Case 1";

TC.type = "API";

TC.createdbyuser = "LastName, FirstName, MiddleInitial";

 

TC.steps =

"* Step 1\r\n"

+ "* Step 2\r\n"

+ "+ Expected result on Step 2.\r\n"

+ "* Step 3";

8. Retrieve the list of custom fields from the test case table using the getCustomFieldsDefinitionList operation.

CField[] fieldDefs = ttsdk.getCustomFieldsDefinitionList(cookie, "Test Case");

TC.customFieldList = new CField [2];

The following example adds data to custom fields. Because CStringField inherits from CField, you can add a CStringField to an array of CField.

CStringField desc = new CStringField();

desc.name = "Description";

desc.value = "This is the first line of the description field.\r\n"

+ "This is the second line of the description field.\r\n";

 

TC.customFieldList[0] = desc;

 

CDropdownField product = new CDropdownField();

product.name = "Product";

product.value = "Product B";

 

TC.customFieldList[1] = product;

9. Finish adding the test case and catch exceptions.

ttsdk.addTestCase(cookie, TC);

Console.WriteLine("Finished adding new test case");

}

catch (Exception e)

{

Console.WriteLine("An exception occurred:");

Console.WriteLine(e.Message);

}

10. End the session and log out of the Helix ALM SDK.

finally

{

if (ttsdk != null && cookie != -1)

{

ttsdk.DatabaseLogoff(cookie);

}

Console.WriteLine("Press any key to exit.");

Console.ReadKey();

}