Difference between revisions of "Test Intro Sample"

From STRIDE Wiki
Jump to: navigation, search
(New page: == Building and Running the Samples == TBD == Test Intro Tests == === TEST_BASICS_CClass === - "C Class" test unit - fixturing - pass/fail macros This example demonstrates the declar...)
 
Line 1: Line 1:
== Building and Running the Samples ==
+
== Tests Description ==
TBD
 
  
== Test Intro Tests ==
+
=== s2_testintro_cclass ===
 +
This example demonstrates the declaration and use of a "C Class" test unit -- a structure with function pointer members and optional member data. It also employs fixturing functions that are automatically called by the STRIDE framework to surround each test case call with setup/teardown functionality. Here, the fixturing simply writes a srLOG message, which can be seen in the test results report.
  
=== TEST_BASICS_CClass ===
+
The following topics provide background information on the the features used in this sample:
- "C Class" test unit
 
- fixturing
 
- pass/fail macros
 
 
 
This example demonstrates the declaration and use of a "C Class" test unit (structure with function pointer members).
 
  
It also employs fixturing functions that are automatically called by the STRIDE framework to surround each test case call with setup/teardown functionality. Here, the fixturing simply writes a srLOG message, which can be seen in the test results report.
+
* [[Scl_test_cclass test_cclass pragma]]
 +
* [[Test_Unit_Pragmas#Fixturing_Pragmas fixturing]]
 +
* [[Pass/Fail_macros pass/fail macros]]
  
The test unit contains two test cases, one of which passes and one of which fails. These both "test" a dummy function that simply returns the integer value it was called with. Pass/Fail macros are used to compare return values with expected results.
+
This test unit contains two test cases, one that passes and one that fails -- both test a function (source under test) that simply returns the integer value it was called with. Pass/Fail macros are used to compare return values with expected results.
  
Note that the test cases are run in the order in which they appear in the "C Class".
+
As with all STRIDE test units, the test cases are executed in the order that they appear in the "C Class".
  
=== TEST_BASICS_FList ===
+
=== s2_testintro_flist ===
 
  - function list test unit
 
  - function list test unit
 
  - pass/fail macros
 
  - pass/fail macros
Line 27: Line 24:
 
It contains three test cases, the first two of which are identical to the "C class" test cases. The third test demonstrates a technique for simple event testing.
 
It contains three test cases, the first two of which are identical to the "C class" test cases. The third test demonstrates a technique for simple event testing.
  
=== TEST_DOUBLES ===
+
=== s2_testintro_testdoubles ===
 
  - mocking
 
  - mocking
 
  - faking
 
  - faking
Line 43: Line 40:
 
: Like the prior mock test, this test effectively performs a dynamic replacement of s2CopyString's call to s2MoveString, this time to a fake implementation named s2MoveString_Fake. Here, s2MoveString_Fake forces an error condition. The testDoubles_Fake test verifies that the error is handled as expected by s2CopySting.
 
: Like the prior mock test, this test effectively performs a dynamic replacement of s2CopyString's call to s2MoveString, this time to a fake implementation named s2MoveString_Fake. Here, s2MoveString_Fake forces an error condition. The testDoubles_Fake test verifies that the error is handled as expected by s2CopySting.
  
=== TEST_POINTS ===
+
=== s2_testintro_testpoints ===
 
     - Event testing
 
     - Event testing
 
     - State testing
 
     - State testing

Revision as of 12:18, 3 June 2009

Tests Description

s2_testintro_cclass

This example demonstrates the declaration and use of a "C Class" test unit -- a structure with function pointer members and optional member data. It also employs fixturing functions that are automatically called by the STRIDE framework to surround each test case call with setup/teardown functionality. Here, the fixturing simply writes a srLOG message, which can be seen in the test results report.

The following topics provide background information on the the features used in this sample:

This test unit contains two test cases, one that passes and one that fails -- both test a function (source under test) that simply returns the integer value it was called with. Pass/Fail macros are used to compare return values with expected results.

As with all STRIDE test units, the test cases are executed in the order that they appear in the "C Class".

s2_testintro_flist

- function list test unit
- pass/fail macros
- test of asynchronous event
- pass/fail as function return value

This example demonstrates the declaration and use of a function list test unit, which is comprised of free functions.

It contains three test cases, the first two of which are identical to the "C class" test cases. The third test demonstrates a technique for simple event testing.

s2_testintro_testdoubles

- mocking
- faking
- pass/fail macros 

This example demonstrates the use of STRIDE's test double technique to implement mocks and fakes. The target of these techniques is the function named s2CopyString.

testDoubles_Normal
This first test case calls s2CopyString function as part of its testing. s2CopyString, as part of its implementation, calls s2MoveString. s2MoveString will be the target of our doubling; we will be able to test the behavior of s2CopyString while dynamically substituting different implementations of s2MoveString.
testDoubles_Mock
This test effectively performs a dynamic replacement of the implementation of the original s2MoveString with a different mock implementation named s2MoveString_Mock. The test calls s2CopyString as before, but within s2CopyString the call is routed to our mock implementation. s2MoveString_Mock verifies that the input string passed to s2CopyString is correctly propagated to its call to s2MoveString.
testDoubles_Fake
Like the prior mock test, this test effectively performs a dynamic replacement of s2CopyString's call to s2MoveString, this time to a fake implementation named s2MoveString_Fake. Here, s2MoveString_Fake forces an error condition. The testDoubles_Fake test verifies that the error is handled as expected by s2CopySting.

s2_testintro_testpoints

    - Event testing
    - State testing
    - Asynchronous testings
testPoints_Event
This test case uses STRIDE test points to verify the state of a counter implemented in the function s2RegCount. The counter is expected to reset to zero after a specific number of function calls. By firing a test point upon reset, the counter can communicate the reset occurrence to the testPoints_Event test.
testPoints_States
This test case uses STRIDE test points to verify the operation of a state machine.
testPoints_Asyn
This test case uses STRIDE test points to verify the receipt of an asynchronous event.