Test Function List Sample: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Introduction ==
== Introduction ==


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 intended as a simple grouping of test functions and are designed to be used with the C language (although it is not restricted from compilation in a C++ environment as well). Test FLists does not support more advanced usages patterns like private test data. If you need more advanced functionality, consider using [[Test Class Samples|Test Classes (c++)]] or [[Test CClass Samples|Test C-Classes]].
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 intended as a simple grouping of test functions and are designed to be used with the C language (although it is not restricted from compilation in a C++ environment as well). Test FLists does not support more advanced usages patterns like private test data. If you need more advanced functionality, consider using [[Test Class Sample|Test Classes (C++)]] or [[Test CClass Sample|Test C-Classes]].


== Tests Description ==
== Tests Description ==
Line 9: Line 9:


==== basic_simple ====
==== 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.
This example demonstrates passing and failing tests using the primary integer (int, short, and char) types that infer status from.


==== basic_fixtures ====
==== basic_fixtures ====
Line 18: Line 18:


==== runtimeservices_simple ====
==== runtimeservices_simple ====
This example shows how to use [[Runtime Test Services#srTestCaseSetStatus|srTestCaseSetStatus]] to set status, [[Runtime Test Services#srTestCaseAddComment|srTestCaseAddComment]] to add a comment, and srTEST_ADD_COMMENT_WITH_LOCATION to add a comment that automatically includes line and file information.
This example shows how to use [[Runtime Test Services#srTestCaseSetStatus|srTestCaseSetStatus]] to set status and [[Runtime Test Services#srTestCaseAddAnnotation|srTestCaseAddAnnotation]] to add a comment.


==== runtimeservices_dynamic ====
==== runtimeservices_dynamic ====
This example shows how to use [[Runtime Test Services#srTestSuiteAddSuite|srTestSuiteAddSuite]], [[Runtime Test Services#srTestSuiteAddCase|srTestSuiteAddCase]], [[Runtime Test Services#srTestSuiteAddAnnotation|srTestSuiteAddAnnotation]], and [[Runtime Test Services#srTestAnnotationAddComment|srTestAnnotationAddComment]] for dynamic suite, test, and annotation creation in the context of a single test method.
This example shows how to use [[Runtime Test Services#srTestSuiteAddCase|srTestSuiteAddCase]], [[Runtime Test Services#srTestCaseAddAnnotation|srTestCaseAddAnnotation]], and [[Runtime Test Services#srTestAnnotationAddComment|srTestAnnotationAddComment]] for dynamic suite, test, and annotation creation in the context of a single test method.


==== runtimeservices_override ====
==== runtimeservices_override ====
Line 27: Line 27:


==== runtimeservices_varcomment ====
==== runtimeservices_varcomment ====
This example demonstrates the use of [http://en.wikipedia.org/wiki/Printf printf] style format strings with [[Runtime Test Services#srTestCaseAddComment|srTestCaseAddComment]].
This example demonstrates the use of [http://en.wikipedia.org/wiki/Printf printf] style format strings with [[Runtime Test Services#srTestCaseAddAnnotation|srTestCaseAddAnnotation]].
 
== Run Tests ==
Now launch the test app (if you have not already) and execute the runner with the following commands:
 
''Test FList tests'':
<pre>
stride --device="TCP:localhost:8000" --database="../out/TestApp.sidb" --run="s2_testflist_basic_fixtures; s2_testflist_basic_simple" --output=FList.xml
</pre>
 
Note the command will produce distinct result files for the run (per the --output command above). Please use the result file to peruse the results by opening each in your browser.
 
== Observations ==
This sample demonstrates a simpler packaging technique that is appropriate for systems that support C compilation only (no C++). [[Test_Units#Test_Units|FLists]] are simple a collection of functions that are called in sequence. There is no shared state or data, unless you arrange to use global data for this purpose. Review the source code in the directory and follow the sample description.
 
The following are some test observations:
 
* flist tests support setup/teardown fixturing, but '''not''' parameterization or exception handling.
* we've again provided documentation using doxygen formatting for these samples. However, because there is no storage-class entity with which the docs are associated in an FList, there are some restrictions to the documentation, which you can read about [[Test_API#Test_FLists|here]].
* notice how the [[Scl_test_flist|scl_test_flist pragma]] requires you to both create a name for the test unit (first argument) '''and''' explicitly list each test method that is part of the unit. This is one disadvantage of flist over a test class (the latter does not require explicit listing of each test since all conforming public methods are assumed to be test methods).
 


[[Category: Samples]]
[[Category: Samples]]

Latest revision as of 19:33, 5 August 2014

Introduction

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 intended as a simple grouping of test functions and are designed to be used with the C language (although it is not restricted from compilation in a C++ environment as well). Test FLists does not support more advanced usages patterns like private test data. If you need more advanced functionality, consider using Test Classes (C++) or Test C-Classes.

Tests Description

Basic

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).

basic_simple

This example demonstrates passing and failing tests using the primary integer (int, short, and char) types that infer status from.

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

These examples cover basic usage of our Runtime Test Services API (as declared in srtest.h).

runtimeservices_simple

This example shows how to use srTestCaseSetStatus to set status and srTestCaseAddAnnotation to add a comment.

runtimeservices_dynamic

This example shows how to use srTestSuiteAddCase, srTestCaseAddAnnotation, and srTestAnnotationAddComment for dynamic suite, test, and annotation creation in the context of a single test method.

runtimeservices_override

This example shows how to use srTestCaseSetStatus to override the status that would otherwise be inferred from the return value.

runtimeservices_varcomment

This example demonstrates the use of printf style format strings with srTestCaseAddAnnotation.

Run Tests

Now launch the test app (if you have not already) and execute the runner with the following commands:

Test FList tests:

stride --device="TCP:localhost:8000" --database="../out/TestApp.sidb" --run="s2_testflist_basic_fixtures; s2_testflist_basic_simple" --output=FList.xml

Note the command will produce distinct result files for the run (per the --output command above). Please use the result file to peruse the results by opening each in your browser.

Observations

This sample demonstrates a simpler packaging technique that is appropriate for systems that support C compilation only (no C++). FLists are simple a collection of functions that are called in sequence. There is no shared state or data, unless you arrange to use global data for this purpose. Review the source code in the directory and follow the sample description.

The following are some test observations:

  • flist tests support setup/teardown fixturing, but not parameterization or exception handling.
  • we've again provided documentation using doxygen formatting for these samples. However, because there is no storage-class entity with which the docs are associated in an FList, there are some restrictions to the documentation, which you can read about here.
  • notice how the scl_test_flist pragma requires you to both create a name for the test unit (first argument) and explicitly list each test method that is part of the unit. This is one disadvantage of flist over a test class (the latter does not require explicit listing of each test since all conforming public methods are assumed to be test methods).