Ask a Question

How to Write TestComplete Test Results to SQL Server

aceishigh
Contributor

How to Write TestComplete Test Results to SQL Server

Hi,

Once my tests have run, I'd like to be able to write them to a sql server databse. This would then be used for reporting services.

Does TestComplete provide any integration with SQL Server to help me do this?

Thanks for your support.

J.
4 REPLIES 4
alevans4
Contributor

RE: How to Write TestComplete Test Results to SQL Server

I don't know of any specific integration, but you can definitely roll your own.  We wrote code that saves the log to a specified directory, and then logs the results to a SQL Server database table that has the test name, results, and a pointer to the log.
aceishigh
Contributor

RE: How to Write TestComplete Test Results to SQL Server

Thanks for your reply Bert, that sounds interesting. Would yu be able to share more detail or even some code on how you did this?

Thanks,

J.
alevans4
Contributor

RE: How to Write TestComplete Test Results to SQL Server

Essentially what I've done is set up event handlers for OnStopTest and OnStartTest.  I'll post examples of what those are below.  We have a database for software testing that contains a TestStatus table that has information about the project and test item,
the time it started and stopped, a status (error, warning, running, ok,
etc), the last error that occurred, and a pointer to a log file of the
run.  OnStartTest I insert a placeholder row into the TestStatus table (via a stored procedure) and then I update the same row in the OnStopTest event. 



We wrote a view that brings up the latest results for all our tests.  You can dump the results of that view into anything, a web page, an email, etc. and see a snapshot of the latest test results.



Here are the OnStartTest and OnStopTest events.  stDB is an instance of a database helper object I wrote that allows you to execute sql or stored procedures against a SQL Server database.



function GeneralEvents_OnStartTest(Sender)

{

  //leave if we're not running in a test item

  if (NotRunningInTestItem()) return;

 

  errors = []; //clear the errors array

  warnings = []; //clear the warnings array

  currentErrorCount = Log.ErrCount;

 

  if (Project.TestItems.Current.Name == GetFirstEnabledTestItemName())

  {

    //first test item in the run--do things that need to be done to prepare the test

    OnBeginTesting();  

  }

  //Log the start to the database

  var aParamArray = new Array();

  aParamArray.push(["TestSectionName", GetProjectName() + "_" + Project.TestItems.Current.Name]);

  aParamArray.push(["TestStatusDesc", "Running"]);

  stDB.ExecuteStoredProc("InsertTestSectionStatus",aParamArray);

 

  //Set the indicator and create a folder

  Indicator.Clear();

  Indicator.PushText(Project.TestItems.Current.Name);

//  Log.PushLogFolder(Log.CreateFolder(Project.TestItems.Current.Name));

}



function GeneralEvents_OnStopTest(Sender)

{

  //This is here to avoid logging/deleting backup files etc, if we're running something

  //outside a test item (ie. rightclick|Run Current Routine)

  if (NotRunningInTestItem()) return;



  //Save the log file for the current test item

  var linkToLog = SaveLog();



  //Save the results to the SoftwareTesting database

  var aParamArray = new Array();

  aParamArray.push(["TestSectionName", GetProjectName() + "_" + Project.TestItems.Current.Name]);

  aParamArray.push(["TestStatusDesc",  GetTestStatus()]);

  aParamArray.push(["TestStatusComments", GetTestStatusComment()]);   

  aParamArray.push(["TestLogPath", linkToLog]);    

  stDB.ExecuteStoredProc("CompleteTestSectionStatus",aParamArray);

 

  //If this was the last test, perform end of test tasks

  if (Project.TestItems.Current.Name == GetLastEnabledTestItemName())

  {

    OnEndTesting();

  }



  Indicator.PopText();

}
MegO
Contributor

Re: RE: How to Write TestComplete Test Results to SQL Server

Hi alevans4,

 

Do you have an example of the stored procedure you used to insert this data please. I am trying to get something similar set up in our environment at the moment.

cancel
Showing results for 
Search instead for 
Did you mean: