This article demonstrates, through a programming example, a method for the automatic logging of test results to a records based format. The techniques presented in this article can be adapted to work with any data storage mechanism. Specifically, the example creates, opens and appends test results to a local CSV file, an ADODB based database, an Excel file, or some combination of the preceding. The code presented in this example reside in the AUTOLOG driver that is included with this article below.
AlgorithmThe process for automatic test logging is as follows:
- Log the test results as they are accumulated
Create the log fileTo ensure that a new record is created each time we run the test program, a new external log file is created in the OnInitProgram() event. In the example, we use three functions within OnInitProgram() to create three different logs: CreateNewCsvFile(), CreateNewExcelFile(), and CreateNewDBTable().
The purpose of creating the log before the tests are run is to both ensure that we are going to be able to save to the target location and to allow ourselves an opportunity to record any header data before the test data begins accumulating.
In the case of logging to a text file, a file needs to be created (storing the file handle in a global variable) and header information including the serial number, start time, program name is recorded. The log file will remain open for the duration of the program execution; we can append test results to the file using the file handle created. CSV is an example of a text file and CreateNewCsvFile() demonstrates this method behavior:
FileWrite(m_hCsv, "Test Id,Test Name,Pin,Unit,Min,Result,Max,Status",,"\r\n")
Accumulating resultsBy the time the OnEndTest() event is called, the Test object will be updated with the latest test results. This is an ideal place to record the latest test results to the log file. In our example, we use three functions within OnEndTest() to append to the logs: AppendCsvResults(), AppendExcelResults(), AppendDBResults().
In the case of appending to a compliant ADODB, the record needs to be accessed and then a new record can be created and filled out. AppendDBResults demonstrates this method:
obRecordSet.Open("SELECT * FROM TestsResults", sConnection, ,adOpenDynamic)
Or Using EXCEL driver (AppendExcelResults()) :
EXCEL Set Value(m_xlWorkbook,,"A"+sCurrentExcelRow, Test.Id)
EXCEL Set Value(m_xlWorkbook,,"F"+sCurrentExcelRow, Test.Result)
Closing the log fileDepending of the record type that you are utilizing, you may need to perform some sort of termination procedure such as writing footers, closing file handles, and releasing objects that were instantiated during the creation phase of the algorithm. This is the complement to the Create- type procedures so it is appropriate to put it in to the OnEndProgram() event.
Using the ExampleThis example workspace attached to this article uses The AUTOLOG Driver Shortcut properties to enable/disable the logging. If the Driver Shortcut properties are empty, no automatic logging will be performed. By default, the properties should be entered as followed: If you like to use the logging in your application, include the AUTOLOG.drv in your project System.
Using these properties will create three files in the C:\ root directory: MyLog.mdb, MyLog.xls and MyLog.csv.
- DatabaseConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\MyLog"
Figure 1. Microsoft Execl XLS File Output
Figure 2. Microsoft Access MDB Database File Output
Where to Go From HereThis example only allows you to log results from Min/Max test types. If the ability to update the properties of another test type were needed, the code in the various Create- and Append- procedures would need to be updated.
Download the AutoLogger Example Files: Click Here