Forum Discussion
alevans4
Contributor
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();
}
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();
}
Related Content
- 4 years ago
- 2 years ago
Recent Discussions
- 14 hours ago
- 15 hours ago