### Initialize Testee and Test Variables in Setup Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_create_unit_test_with_test_blocks.html Initialize the testee and any test-specific variables within the Setup method. This method is called once before the Execute method. Example initializes a CTU counter and resets a cycle counter. ```structured-text // Initialize the testee counter(CU:=FALSE, RESET:=TRUE, PV:=5); // reset the counter, set expected upper limit // Initialize the test itself cycleCounter := 0; // we'll count cycles ``` -------------------------------- ### Parameter Placeholder Example Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_test_action_monitoring_readvariable.html Demonstrates how to use a parameter as a placeholder in the configuration tab by enclosing its name in braces. ```Placeholder Syntax {name} ``` -------------------------------- ### Example CODESYS Command Line Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_cmd_copy_command_line_to_clipboard.html This example shows the full command-line command generated for executing a test script, including all necessary parameters. The command is copied to the clipboard for direct use. ```bash "C:\Program Files\CODESYS 3.5.18.0\CODESYS\Common\CODESYS.exe" --profile="CODESYS V3.5 SP18" --exitafterexecutecommand --executecommand="TestManager ExecuteScript" --arg1:"--repository-location=D:\Testrepository_1" --arg2:"--script=Examples.ApplicationTest" --arg3:"--version=4.2.3.0" --arg4:"--tester=mr.nobody" --arg5:"--save-xml=C:\Users\mr.nobody\Documents\TestManagerReports\Examples.ApplicationTest(4.2.3.0).xml" --arg6:"--save-html=C:\Users\mr.nobody\Documents\TestManagerReports\Examples.ApplicationTest(4.2.3.0).html" --arg7:"--progress=stdout;window" ``` -------------------------------- ### Assert String Starts With Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_assert_functions.html Checks if an actual string value starts with a reference string value. Use this to verify the beginning of a string. ```IEC 61131-3 Assert_String_StartsWith(THIS^, , , "") ``` -------------------------------- ### Example POU Selection for Test Run Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_elem_unit_test.html Demonstrates how to specify POUs for inclusion in a test run using various naming conventions and wildcards. ```text TestCase_01 tc1 tc? TestCase_0* *_01 ``` -------------------------------- ### Test Script Variable Example Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_test_action_monitoring_readvariable.html Provides an example of a test script variable name that can be used with input or output parameters. ```Test Script Variable TS_CaseA_Result ``` -------------------------------- ### Example Test Table Name Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_struct_automate_test_with_test_table.html This is an example of a test table name used in CODESYS projects. ```text Examples.CounterTestTable ``` -------------------------------- ### Implementation for Test Case Setup Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_elem_unit_test.html This code snippet demonstrates the implementation within a test case, setting the test case name, categories, and timeout. It is typically used when `THIS^.xGetTestInfo` is true to configure test case metadata. ```iecst CASE diTestCaseIndex OF 0: // Test Case #0 - tests the same as CTD_InitialValue IF THIS^.xGetTestInfo THEN // Test case header THIS^.wsTestCaseName := "TestStep #0: Intial value"; THIS^.wsTestCaseCategories := "Multitest"; THIS^.diTestCaseTimeout := 200; xDone := TRUE; ELSE ... ``` -------------------------------- ### PLC Variable Path Example Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_test_action_monitoring_readvariable.html Specifies the full IEC path for a variable to be read from the controller. The Input Assistant can help with auto-completion. ```IEC Path Application2.PLC_PRG.iResult ``` -------------------------------- ### Output Parameter Name Example Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_test_action_monitoring_readvariable.html Defines the name of the output parameter, which is used to pass values back to the test script. This name is specified without quotation marks. ```Parameter Name {APP2_Result} ``` -------------------------------- ### Example CODESYS Time Format for Global Timeout Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_struct_automate_test_with_test_table.html Specifies a global timeout of 5 seconds for a test table in CODESYS using the T# time format. ```text T#5s ``` -------------------------------- ### Implement Test Logic in prvCyclicAction Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_implement_multi_test_pou.html Implement the test logic within the prvCyclicAction method, which is called until xDone is TRUE. This example shows a single test case (CASE 0) for counting. ```IEC 61131-3 Structured Text SUPER^.prvCyclicAction(); // mandatory - dont' change CASE diTestCaseIndex OF 0: // test case #0; add test cases as new CASEs IF xGetTestInfo THEN // initializate test case // define mandatory test case information wsTestCaseName := "Count from 0 to 5"; wsTestCaseCategories := "CTU"; diTestCaseTimeout := 500; xDone := TRUE; // signal test case initialization done ELSE IF (cycleCounter = 0) THEN // prepare test case counter(CU:=FALSE, RESET:=TRUE, PV:=5); // stimulate testee as long as we expect: 5 rising edges to count to 5 equals minimum 10 cycles ELSIF (cycleCounter < 10) THEN // check: counter limit not reached yet TM.Assert_Bool_IsFalse(THIS^, counter.Q, "Counter signaled limit reached prematurely"); TM.Assert_Word_Less(THIS^, 5, counter.CV, "Counter reached limit unexpectedly"); counter(CU:= (NOT counter.CU), RESET:=FALSE); // Trigger counter with rising edges xDone := FALSE; // signal test still running ELSE // check: counter reached limit TM.Assert_Bool_IsTrue(THIS^, counter.Q, "Counter did not signal limit reached"); TM.Assert_Word_Equal(THIS^, 5, counter.CV, "Counter did not reach limit"); xDone := TRUE; // mandatory: signal test completed END_IF IF xDone OR xError THEN cycleCounter := 0; // clean up for next test case ELSE cycleCounter := cycleCounter + 1; // count cycles END_IF END_IF ELSE IF diTestCaseIndex < 0 THEN // mandatory, signal number of test cases, if called with (diTestCaseIndex < 0) diTestCaseCount := 1; xDone := TRUE; ELSE // mandatory, don't remove: fail for invalid test case index wsInfo := "Invalid test case index"; iError := 2; END_IF END_CASE ``` -------------------------------- ### Example CODESYS Time Format for Local Timeout Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_struct_automate_test_with_test_table.html Specifies a local timeout of 1 second for a test case group or test case within a CODESYS test table. ```text T#1s ``` -------------------------------- ### Stimulate Testee and Check Results in Execute Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_create_unit_test_with_test_blocks.html Implement the core test logic in the Execute method, which is called repeatedly until it returns TRUE. This involves stimulating the testee and checking its results using assertion methods. The example stimulates a CTU counter and asserts its final state. ```structured-text cycleCounter := cycleCounter + 1; // count cycles IF (cycleCounter <= 10) THEN // stimulate testee as long as we expect: 5 rising edges to count to 5 equals minimum 10 cycles // stimulate testee counter(CU:= (NOT counter.CU), RESET:=FALSE); // Trigger counter with rising edges Execute := FALSE; // signal test still running ELSE // check result with suitable assertions for any occasion TM.Assert_Bool_IsTrue(THIS^, counter.Q, "CTU did not signal that it's limit was reached"); TM.Assert_Word_Equal(THIS^, 5, counter.CV, "CTU did not reach expected limit"); Execute := TRUE; // mandatory: signal test completed END_IF ``` -------------------------------- ### SUBSTRING Macro Syntax Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_macro.html Extracts a segment from a string or variable based on start position and length. ```CODESYS Macro SUBSTRING( | , , ) ``` -------------------------------- ### Using Arithmetic Operators (MOD, DIV, /) Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_expression.html Demonstrates the use of modulo, integer division, and floating-point division operators. Note that MOD and DIV operate only on integers, while '/' performs floating-point division if a real value is involved. ```Test Script real := thirtySix MOD 11 DIV 2 / 4.0 integer := thirtySix MOD 11 DIV 2 / four ``` -------------------------------- ### Initialize Testee and Control Variables in prvStart Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_implement_multi_test_pou.html Initialize the testee instance and any control variables in the prvStart method. This method is called once before prvCyclicAction. ```IEC 61131-3 Structured Text SUPER^.prvStart(); // mandatory - don't change // Initialize the testee counter(CU:=FALSE, RESET:=TRUE); // reset the counter; note: initialization per test case must be performed in prvCyclicAction // Initialize test control variable for first test case cycleCounter := 0; ``` -------------------------------- ### Declare Variables for FB_RIGHT Function Block Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_iec_unit_test_example_right.html Declare input and output variables for a function block that will wrap the RIGHT string function. This setup is necessary for indirect testing of the RIGHT function. ```Structured Text VAR_INPUT strCompleteString : STRING(255); iSize: INT; END_VAR VAR_OUTPUT strResult : STRING (255); END_VAR ``` -------------------------------- ### Configure Progress Output Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_command_line_commands.html Configures the display of test run progress. Progress data can be sent to a file, standard output, standard error, or the Test Manager UI. ```bash --progress= ``` ```bash --progress=none ``` ```bash --progress=stdout ``` ```bash --progress=stderr ``` ```bash --progress=window ``` ```bash --progress=D:\tm.log.txt;stdout;window ``` -------------------------------- ### Execute Test Script with Repository Location Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_command_line_commands.html Executes a test script, specifying the repository location, script path, version, and progress output. The progress output can be directed to standard output and the Test Manager UI. ```bash --arg1:"--repository-location=D:\Test repository_1" –-arg2:"—script=foo/bar" –-arg3:"—version=1.2.3.0" --arg4:"--progress=stdout;window" ``` -------------------------------- ### Specify Script Version Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_command_line_commands.html Sets the version of the test script to be used. If omitted, the newest version is automatically selected. ```bash --version=1.2.3.4 ``` -------------------------------- ### Execute Test Script Command Line Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_command_line_commands.html Executes a test script using CODESYS.exe with specified profile, command, and script arguments. Arguments containing spaces or special characters should be enclosed in quotation marks. ```bash C:\Program Files (x86)\3S CODESYS\CODESYS\Common\CODESYS.exe --profile="CODESYS V3.5 SP13" --executecommand="TestManager ExecuteScript" --arg1:"--repository-name=ABC" --arg2:"--script=SaveBootProject" --arg3:"--version=1.0" --arg4:"--tester=autobuild" –arg5:"--store" ``` -------------------------------- ### Specify Test Repository Location Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_command_line_commands.html Sets the absolute path for the test repository. This parameter is an alternative to specifying the repository name. ```bash --repository-location="D:\Test Manager\TestRepository_1" ``` -------------------------------- ### Specify Script Path Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_command_line_commands.html Defines the path and name of the script within the test repository. Hierarchical folders are separated by periods. ```bash --script=FOLDER_ABC.FOLDER_A.Test_Feature_A ``` -------------------------------- ### Declare Testee Instance and Control Variables Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_create_unit_test_with_test_blocks.html Declare an instance of the component under test (testee) and any necessary control variables in the declaration part of the test POU. Attributes like 'test' and 'testcasename' can be added for test configuration. ```structured-text {attribute 'test'} {attribute 'testcasename':='TC01'} {attribute 'testcasetimeout':='15000'} FUNCTION_BLOCK TestCase EXTENDS TM.Testcase VAR_INPUT END_VAR VAR_OUTPUT END_VAR VAR counter : CTU; // testee instance cycleCounter : INT; // independant test control variable END_VAR ``` -------------------------------- ### Assignment with AND Operator Source: https://content.helpme-codesys.com/en/CODESYS%20Test%20Manager/_tm_expression.html Demonstrates the use of the AND logical operator. The 'and' variable will be false in the first case and true in the second. ```CODESYS Script and := true AND false and := true AND true ```