Logging ATEasy Test Results to a CSV file, Excel worksheet, or a Database

Knowledge Base Article # Q200248

Read Prior Article Read Next Article
Summary This article discusses ways to incorporate automatic logging into your project using various formats from an ATEasy application.
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.


The process for automatic test logging is as follows:
  • Create the log file
  • Log the test results as they are accumulated
  • Finalize the log file

Create the log file

To 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 results

By 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 file

Depending 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 Example

This 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.
  • DatabaseConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\MyLog"
  • ExcelFile = "C:\MyLog"
  • CsvFile = "C:\\MyLog"
Using these properties will create three files in the C:\ root directory: MyLog.mdb, MyLog.xls and MyLog.csv.

The XLS created by the Autologger driver

Figure 1. Microsoft Execl XLS File Output

The MDB created by the Autologger driver

Figure 2. Microsoft Access MDB Database File Output

Where to Go From Here

This 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
Article Date 4/16/2014 5:24:53 PM     Updated: 4/16/2014 5:30:56 PM
Keywords ATEasy, CSV, ADODB, Database, Excel, Logging, Automated

1 ratings | 5 out of 5
View Comment
Rating: 5 out of 5 | Andrew Y. from Bristol, PA | Wednesday, October 7, 2015
Very slick
Read Prior Article Read Next Article