2.4. Handling Input/Output Data

2.4.1. Handling Ground Truth Data

In almost all cases, testing requires verifying computed results against some sort of ground truth data. This data could be anything from simple numbers to images. While simple data types are part of the test case scripting, files must be made available to the testing process.

2.4.1.1. Using Local Data

Each test case can have a directory for all required data. By default, this directory, named “data”, is located in the local folder of the test case. By using the “dataDirectory” keyword in the definition file, this default value can be changed.

Having ground truth data in the test case folder has one major drawback: it requires the data to be checked in to the version control system and to be part of the installer. This is not an option if the data exceeds a few megabytes. Therefore, there is an option to use external data storage, such as a network share.

2.4.1.2. Using an External Data Storage

[Note] Note

Never try to connect to a network share directly via a fixed URL like \\fileserver\testcenter-data , as this is not supported on all platforms and will cause problems if the resource is not available.

To connect external data storage, use the ctx.expandFilename method. It expands variables that are either predefined or set in the MeVisLab preferences file. This way, the path to the share can be given in the .prefs file, and the share can be loaded on all platforms. Having the share defined in the .prefs file instead of a dozen test files also makes changing the path much easier, for example, if the share has to be moved.

The following .prefs file defines two shares for TestCenter data for use on Windows:

Settings {
    TESTCENTER_EXTERNAL_DATA_MMS = \\fs.mms.example\tc
    TESTCENTER_EXTERNAL_DATA_FME = \\fs.fme.example\tc
}
                        

With these two variables set, the filename ${TESTCENTER_EXTERNAL_DATA_MMS}/testcasename/filename can be used to access the file via the expandFilename method, which resolves the actual path.

[Note] Note

expandFilename will only expand known variables. If a test case is instantiated at a site that does not have access to the resource, the variable is not specified, and the result will be an invalid path and an error. To prevent problems, use the Base.getExternalDataDirectory method, which returns None if the variable is not defined, and the path otherwise.

2.4.2. Handling Result Data

Test cases must be able to create results. The result files must be saved and added to the report. The location for saving files should be retrieved using the getResultDirectory method. Using other directories is possible but not recommended. Only the retrieved result directories are cleaned up when starting the next test run.

The files created in test functions do not appear in the report automatically. They must be added explicitly using one of the following two methods:

  • showFile: Adds a download link for a file

  • showImage: Directly inserts an image into the report

Both methods add special messages to the log file. The result handlers detect these messages, copy the linked files, and add them to the report.

2.4.3. Result Handling

The master collects all the results the slave created while testing and stores them for later use. As local and automatic testing have different requirements for presenting the results, the master uses an XML file as an intermediate representation. Results are saved to a file after all tests have been finished.

The structure of the result file is mostly taken from the responses sent by the slave. It contains information about all executed test cases, all modules being tested, and the results of the actual tests. This information is used to create a detailed report.

[Note] Note

The further processing of the XML file is not handled by the TestCenter but by the calling mechanism. For local testing, there are methods that convert the results to static HTML pages. For automatic testing, those results are written to a database. The presentation of the results is therefore handled by another entity. For more information, see Chapter 4, TestCenter Reports.