Creating a Bug in Quality Center using the OTA API

I’ve had several requests for more examples using the OTA API. This is a companion piece with the previous post about Executing Tests in Quality Center using the OTA API.

If you’re running tests outside of Quality Center, some are bound to fail. And if you have to write a defect in QC to associate with the test, why should you have to open it up just for that.

While I don’t currently have a access to a working copy of QC to test it, creating a bug is pretty straightforward.

Once you have a connection established

TDConnection connection = new TDConnection();
connection.InitConnectionEx(qcUrl);
connection.ConnectProjectEx(qcDomain, qcProject, qcLoginName, qcPassword);

You can get the BugFactory and create a bug with AddItem()

BugFactory bugFactory = connection.BugFactory;
Bug bug = bugFactory.AddItem(null);

AddItem() takes an object with data, but we can add the data manually

bug.Status = "New";
bug.Project = "QCIntegration";
bug.Summary = "Short description of the bug";
bug.DetectedBy = "Aaron Evans";
bug.AssignedTo = "Nobody";
bug.Priority = "Low";

Finally, when you’re done updating your bug, you call Post() to save it.

bug.Post();

There are some tricks for adding attachments and associating a bug with a test run, but I won’t go into that now.

Here’s the gist of this example. And it’s also included in the QCIntegration Examples.

8 thoughts on “Creating a Bug in Quality Center using the OTA API

  1. hI Can you please let me know how to add the other fields available in QC ,namely ‘status code’ ‘module’…etc ..in the above same program

    1. Hi Hari

      I also need the same. Can you please tell me something ? What can i do to get the newly created defect ?
      It would be really helpful. Thanks

    1. Hi,
      Thanks for this code. It worked nicely.
      I will be great full to you if can share a code for adding single/multiple attachments.

Leave a comment