winIDEA SDK
Loading...
Searching...
No Matches
programmatic_test_case_creation.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
import isystem.connect as ic
def configure_test_reports(test_bench: ic.CTestBench):
report_config = test_bench.getTestReportConfig(False)
report_config.setReportContents(ic.CTestReportConfig.RCONFIG_FULL)
report_config.setOutputFormat(ic.CTestReportConfig.FMT_XML)
report_config.setFileName('myTestReport.xml')
report_config.setIncludeTestSpec(False) # no test case definition in report file
def create_test_case(velocity, accel, ret_val_value, function_name):
test_spec = ic.CTestSpecification()
test_func = test_spec.getFunctionUnderTest(False)
test_func.setName(function_name)
params = ic.StrVector()
params.append(str(velocity))
params.append(str(accel))
test_func.setPositionParameters(params)
test_func.setRetValueName('retVal')
results = ic.StrVector()
results.append(f'retVal == {ret_val_value}')
test_spec.setExpectedResults(results)
return test_spec
def main():
# This object will contain not only test cases, but also
# configuration for test execution and test reports.
test_bench = ic.CTestBench()
configure_test_reports(test_bench)
# Let's create two test cases
test_case1 = create_test_case(velocity=10, accel=20, ret_val_value=30,
function_name='calculate')
test_case2 = create_test_case(velocity=-10, accel=-20, ret_val_value=-30,
function_name='calculate')
# This test case is container for other test cases.
root_test_case = test_bench.getTestSpecification(False)
root_test_case.addChildAndSetParent(-1, test_case1)
root_test_case.addChildAndSetParent(-1, test_case2)
# save tests to file
test_bench.save('myTests.iyaml', False, False)
if __name__ == '__main__':
main()