Test Function List Sample: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
== Introduction == | == Introduction == | ||
The Test Function List Samples are part of the [[Test_Unit_Samples|STRIDE Test Unit Samples]]. Function Lists are abbreviated as 'FList' in both pragmas (as in scl_test_flist) and documentation. The Test FList Samples pertain to test units that contain lists of functions to be executed. The Test FList functionality is designed to be used for the C language (although it is not restricted from compilation in a C++ environment as well). | The Test Function List Samples are part of the [[Test_Unit_Samples|STRIDE Test Unit Samples]]. Function Lists are abbreviated as 'FList' in both pragmas (as in [[scl_test_flist]]) and documentation. The Test FList Samples pertain to test units that contain lists of functions to be executed. The Test FList functionality is designed to be used for the C language (although it is not restricted from compilation in a C++ environment as well). | ||
== | == Building and Running the Samples == | ||
Please refer to the section appropriate for your target build environment: | |||
*[[Building and Running Test Unit Samples Under Windows| Windows Off-Target]] | |||
*[[Building and Running Test Unit Samples Under Linux|Linux]] | |||
*[[Building and Running Test Unit Samples Under WinMobile|WinMobile]] | |||
== Sample Test FLists == | == Sample Test FLists == | ||
Once you have built the target application and executed the test flists it contains, you can take time to peruse the test flist source within the STRIDE Studio Project. This section provides a brief description for each. The names of the sections align with the names of the project folders within the STRIDE Studio Project. | |||
=== Basic Examples === | === Basic Examples === |
Revision as of 17:15, 20 April 2009
Introduction
The Test Function List Samples are part of the STRIDE Test Unit Samples. Function Lists are abbreviated as 'FList' in both pragmas (as in scl_test_flist) and documentation. The Test FList Samples pertain to test units that contain lists of functions to be executed. The Test FList functionality is designed to be used for the C language (although it is not restricted from compilation in a C++ environment as well).
Building and Running the Samples
Please refer to the section appropriate for your target build environment:
Sample Test FLists
Once you have built the target application and executed the test flists it contains, you can take time to peruse the test flist source within the STRIDE Studio Project. This section provides a brief description for each. The names of the sections align with the names of the project folders within the STRIDE Studio Project.
Basic Examples
These examples cover the simplest, easiest way to code STRIDE scl_test_flist functionality. These examples use simple POD return types to indicate status and do not annotate the tests with any rich information (such as comments).
01_01_Basic_Simple
This example demonstrates passing and failing tests using the primary POD types that infer status from (int, bool, short, and char). The bool type is only accepted in C++ mode.
01_02_Basic_Fixtures
This example shows how to use setup and teardown fixtures. The setup and teardown methods are called immediately before and after the execution of each test method, respectively.
Runtime Services Examples
These examples cover basic usage of our Runtime Test Services API (as declared in srtest.h).
02_01_RuntimeServices_Simple
This example shows how to use srTestCaseSetStatus to set status, srTestCaseAddComment to add a comment, and srTEST_ADD_COMMENT_WITH_LOCATION to add a comment that automatically includes line and file information.
02_02_RuntimeServices_Dynamic
This example shows how to use srTestSuiteAddSuite, srTestSuiteAddCase, srTestSuiteAddAnnotation, and srTestAnnotationAddComment for dynamic suite, test, and annotation creation in the context of a single test method.
02_03_RuntimeServices_Override
This example shows how to use srTestCaseSetStatus to override the status that would otherwise be inferred from the return value.
02_04_RuntimeServices_VarComment
This example demonstrates the use of printf style format strings with srTestCaseAddComment.
Test FList Execution
This sample demonstrates two different techniques for executing scl_test_flist code.
Commandline Execution
Command line execution for TestFlist is done using the TestUnitRun utility. Here are several examples of specific syntax to execute function lists. All of these commands can be invoked from a standard command shell and the arguments shown assume that the commands are executed with the sample's directory as the starting directory. You must have your TestFList.exe application running in order for the runner to be able to initiate a connection to the target simulator. In addition, you should verify that your %STRIDE_DIR%\bin\transport.cfg file is using the TCP transport to connect to port 8000 (these are the default settings when the product is installed).
Simple execution of all test units
The following command executes all of the test units found in the STRIDE database you have previously generated. For the purpose of this sample, since there is only one database, the -d parameter is not strictly needed, but it is shown here for completeness.
TestUnitRun.pl -d TestFList.sidb
This command executes all Test Units found in the (TestFList.sidb) database in descending alpha-numeric sort order. Any Test FList initialization arguments are given default values (typically zero or NULL).
When you run this command, you should see the following:
Attempting connection using [Sockets (S2)] transport ... Connected to device. Initializing STRIDE database objects... Done. Running Test Basic_Fixtures... Running Test Basic_Simple... Running Test RuntimeServices_Dynamic... Running Test RuntimeServices_Override... Running Test RuntimeServices_Simple... Running Test RuntimeServices_VarComment... Disconnected from device. Test Results saved to C:\STRIDE\Samples\TestUnits\TestFList\TestFList.xml Test Report saved to C:\STRIDE\Samples\TestUnits\TestFList\TestFList.html *************************************************************************** Results Summary *************************************************************************** Passed: 16 Failed: 6 In Progress: 1 Not Applicable: 1 ...in 7 suites. ***************************************************************************
Execution based on an order file
TestUnitRun can optionally base its execution on simple text file input. A simple order file, RunSimple.txt, is provided which specifies a subset of all the function list tests in this sample. This order file also shows how to create subsuites in the final output by using the special {suitepath} syntax, as described in the usage section.
TestUnitRun.pl -d TestFList.sidb -o RunSimple.txt
...and will produce this output:
Attempting connection using [Sockets (S2)(debug)] transport ... Connected to device. Initializing STRIDE database objects... Done. Running Test Basic_Simple... Running Test RuntimeServices_Simple... Disconnected from device. Test Results saved to C:\STRIDE\Samples\TestUnits\TestFList\TestFList.xml Test Report saved to C:\STRIDE\Samples\TestUnits\TestFList\TestFList.html *************************************************************************** Results Summary *************************************************************************** Passed: 8 Failed: 4 In Progress: 1 Not Applicable: 1 ...in 4 suites. ***************************************************************************
Execution based on file system order
TestUnitRun can also try to infer execution order and suite hierarchy from filesystem organization. If you have organized your function list test source files (only the files that contain the scl_test_flist pragma matter here) in a filesystem hierarchy that you want to mimic in your tests, you can specify a root of a directory tree that contains the relevant test flist source. TestUnitRun will walk the directory structure and determine order and hierarchy of tests based on the directory structure. To see an example of this in action, you can execute this command with the sample:
TestUnitRun.pl -d TestFList.sidb -f Tests
This will cause the runner to examine the Tests subdirectory structure and build a hierarchy of tests based on that directory tree. Subdirectories will map to suites in the final report. Here is the output for this example:
Attempting connection using [Sockets (S2)] transport ... Connected to device. Initializing STRIDE database objects... Done. Running Test Basic_Simple... Running Test Basic_Fixtures... Running Test RuntimeServices_Simple... Running Test RuntimeServices_Dynamic... Running Test RuntimeServices_Override... Running Test RuntimeServices_VarComment... Disconnected from device. Test Results saved to C:\STRIDE\Samples\TestUnits\TestFList\TestFList.xml Test Report saved to C:\STRIDE\Samples\TestUnits\TestFList\TestFList.html *************************************************************************** Results Summary *************************************************************************** Passed: 16 Failed: 6 In Progress: 1 Not Applicable: 1 ...in 7 suites. ***************************************************************************
Workspace-based Execution
TestFList.ssw, a workspace in the TestFList directory, demonstrates the use of script execution with Studio to manage test order and hierarchy. This workspace was created using WorkspaceSetup.pl. The setup and teardown folders provided basic infrastructure scripts that start/stop the simulator application (TestFList.exe) and to manage traceviews used for srPrint message collection. The scripts that drive the testing are in the workspace test folder. What follows is a brief description for each.
RunAll
This folder contains a script, All.js, that iterates through the entire collection of test units and executes them one at a time. The order of execution will be in ascending alpabetical order (by name) since the ArrangeBy collection method was called.
Run Individual
This folder shows how to use individual scripts to execute scl_test_flist tests. Each script has the following form:
ascript.TestUnits.Item(TEST_FList_NAME).Run();
The TEST_FList_NAME is the name of the scl_test_flist test to be run. The order and hierarchy of each item may be changed via the Studio tree control by moving the item within the scripts and/or folders. The sample contains individual scripts for a few of the sample scl_test_flist tests - you are free to move, add, or delete any items as you experiment with the workspace.