-
Notifications
You must be signed in to change notification settings - Fork 0
ut_kvp_profile: Key‐Value Pair Assertions for Unit Testing
The ut_kvp_profile.h
header is an extension of the ut_kvp
framework, specifically designed for streamlined assertions within unit tests. It leverages the key-value pair (KVP) structure to simplify the validation of test results against expected outcomes.
- Simplified Assertions: Provides a concise syntax for common assertions (equality checks, string comparisons, etc.) using KVPs.
- Test Case Configuration: Enables loading of expected test results from YAML/JSON files for easy management and maintenance.
-
Error Reporting: Integrates with the
ut_log
module to provide clear and informative error messages upon assertion failures. -
Integration with ut-core: ut_kvp_profile support is provided by default when using ut-core via the
-p
switch.
- Create a Configuration File:
test_case_1:
expected_result: true
test_case_2:
expected_result: 12345
- Start the test and specify the profile file
- Passing a profile into the testing suite, will automatically open the profile
./hdmi_cec -p hdmi_one_port_no_extendedEnums.yml
- Use Assertions:
Macro's are now active and available for use in the test suite.
bool result = my_function();
UT_ASSERT_EQUAL_KVP_PROFILE_BOOL(result, "test_case_1/expected_result");
The ut_kvp_profile
module seamlessly integrates with the ut_log
module to provide informative logging upon assertion failures. For example, the following code:
UT_ASSERT_EQUAL_KVP_PROFILE_BOOL(false, "test_case_1/expected_result");
would result in a log message similar to:
Assertion failed: test_case_1/expected_result (expected: true, actual: false)
The header defines several macros for common assertion types:
UT_ASSERT_EQUAL_KVP_PROFILE_BOOL(checkValue, key)
UT_ASSERT_EQUAL_KVP_PROFILE_UINT8(checkValue, key)
UT_ASSERT_EQUAL_KVP_PROFILE_UINT16(checkValue, key)
UT_ASSERT_EQUAL_KVP_PROFILE_UINT32(checkValue, key)
UT_ASSERT_EQUAL_KVP_PROFILE_UINT64(checkValue, key)
UT_ASSERT_EQUAL_KVP_PROFILE_STRING(checkValue, key)
These macros compare a given checkValue
against the value associated with the specified key
in the KVP data structure. If the values don't match, an assertion failure is triggered.
The header defines several macros for common get types:
UT_KVP_PROFILE_GET_BOOL(key)
UT_KVP_PROFILE_GET_UINT8(key)
UT_KVP_PROFILE_GET_UINT16(key)
UT_KVP_PROFILE_GET_UINT32(key)
UT_KVP_PROFILE_GET_UINT64(key)
UT_KVP_PROFILE_GET_LIST_COUNT(key)
UT_KVP_PROFILE_GET_STRING(key, pszReturnedString )
For more detailed information of operation see the header file ut_kvp_profile.h
-
!include
is supported in the yaml files see ut_kvp: Support for Includes in YAML files, it is extremely important that shared features are segmented into independent files. - Upgrades to the system are coming to allow multiple profile support e.g.
-p a.yaml -p b.yaml
See: #78 - For detailed information on the
ut_kvp
module see ut_kvp: A Flexible Key-Value-Pair Framework