Skip to content

Repeatable Unit Tests

Steve Ives edited this page Apr 27, 2020 · 8 revisions

Harmony Core Logo

Repeatable Unit Tests

Successful repeatable unit tests require data that is the same with each run, as well as test constants (key values) that are used with every run. Solutions created from the harmony core solution templates include functionality that makes it easy to create a unit test project (see Unit Testing) and functionality that makes it easy to set up data and constants for repeatable unit testing.

Using ENABLE_CREATE_TEST_FILES

With a solution created from the harmonycore template, the easiest way to ensure that unit tests are repeatable is to instruct Harmony Core to rebuild the data prior to each unit test run. You can do this by uncommenting the following CodeGen setting in regen.bat:

    set ENABLE_CREATE_TEST_FILES=-define ENABLE_CREATE_TEST_FILES

This option replaces the data files in the directory specified by DATA_FOLDER in UserDefinedTokens.tkn. Note that this option requires both a .txt file and an XDL file for each data file.

Restoring Valid Data

As part of your build, you can copy test-ready versions of your ISAM files to the folder specified by DATA_FOLDER in UserDefinedTokens.tkn. Because DATA_FOLDER is used for a hierarchical search that starts from the current working directory, it is best to create a folder with the specified name in the Services.Test folder and then copy test-ready data (ISAM files) to that folder with each build. (The Services.Test folder is created by GodeGen when the ENABLE_UNIT_TEST_GENERATION option is set in regen.bat.) If the data folder is in Services.Test, your web service won’t use that data for production operations.

Establishing Test Constants

Along with data that is always the same, repeatable unit tests require test constants—i.e., a set of key values that can be used repeatedly to verify that relations and operations are working correctly. These are supplied by TestConstants.Values.dbl, which is created by CodeGen in the Services.Test directory if the ENABLE_UNIT_TEST_GENERATION option is set in regen.bat. This file is generated the first time you generate unit tests, but once this file has been edited, it will not be generated (i.e., your changes won't be overwritten). As generated, TestConstants.Values.dbl has meaningless default values. You must replace the default values with values that work for your data, and you must maintain this file.

Clone this wiki locally