Test Intro Sample: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
Line 3: Line 3:
=== s2_testintro_cclass ===
=== 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.
This example covers the following topics:


The following topics provide background information on the the features used in this sample:
* [[scl_test_cclass|test_cclass test units]]
 
* [[scl_test_cclass|test_cclass pragma]]
* [[Test_Unit_Pragmas#Fixturing_Pragmas|fixturing]]
* [[Test_Unit_Pragmas#Fixturing_Pragmas|fixturing]]
* [[Pass/Fail Macros|pass/fail macros]]
* [[Pass/Fail Macros|pass/fail macros]]


This test unit contains the following test cases:
This demonstrates the declaration and use of a "C Class" test unit -- a structure with function pointer members and optional member data. The test unit contains the following test cases:


; testBasics_PASS
; testBasics_PASS
Line 24: Line 22:
=== s2_testintro_flist ===
=== s2_testintro_flist ===


This example demonstrates the declaration and use of a function list test unit (flist) which is made up of individual [http://en.wikipedia.org/wiki/C_linkage C linkage] test functions. The flist pragma is documented [[scl_test_flist|here]]. Flists are the simplest kind of test unit that can be created for c-only compilation units, but they lack some of the capabilities of CClass test units (such as member data and the ability to use non-extern functions as tests).
This example covers the following topics:
 
* [[scl_test_flist|test_flist test units]]
* [[Pass/Fail Macros|pass/fail macros]]
* asynchronous code validation
 
This example demonstrates the declaration and use of a function list test unit (flist) which is made up of individual [http://en.wikipedia.org/wiki/C_linkage C linkage] test functions. Flists are the simplest kind of test unit that can be created for c-only compilation units, but they lack some of the capabilities of CClass test units (such as member data and the ability to use non-extern functions as tests).


This test unit contains three test cases: the first two are identical to the CClass example above. The third test - testBasics_Asyn_PASS - demonstrates a technique for simple asynchronous event testing by creating a timer using the [[Platform Abstraction Layer|PAL API]] and validating that the registered callback was invoked.
This test unit contains three test cases: the first two are identical to the CClass example above. The third test - testBasics_Asyn_PASS - demonstrates a technique for simple asynchronous event testing by creating a timer using the [[Platform Abstraction Layer|PAL API]] and validating that the registered callback was invoked.


=== s2_testintro_testdoubles ===
=== 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.
This example covers the following topics:
 
* [http://xunitpatterns.com/Mock%20Object.html mock functions]<ref>[http://xunitpatterns.com/Mocks,%20Fakes,%20Stubs%20and%20Dummies.html mocks, fakes, and stubs]</ref>
  * [http://xunitpatterns.com/Mock%20Object.html fake functions]
* [[Pass/Fail Macros|pass/fail macros]]
 
This example demonstrates the use of STRIDE's test double technique to implement mocks and fakes. The function being doubled for these examples is ''s2CopyString'' (in s2_testintro_source.c). The example includes the following test cases:


;testDoubles_Normal
;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.
: 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
;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.
: does 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
;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.
: like the previous test, does a dynamic replacement of s2CopyString's call to s2MoveString, this time to a fake implementation named s2MoveString_Fake. In this case, s2MoveString_Fake forces an error condition. The testDoubles_Fake test verifies that the error is handled as expected by s2CopySting.


=== s2_testintro_testpoints ===
=== s2_testintro_testpoints ===
    - Event testing
 
    - State testing
This example covers the following topics:
    - Asynchronous testings
 
* event verification
  * state verification
* asynchronous code validation
 
The example includes the following test cases:


;testPoints_Event
;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.
: 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
;testPoints_States
: This test case uses STRIDE test points to verify the operation of a state machine.
: uses STRIDE test points to verify the operation of a state machine.


;testPoints_Asyn
;testPoints_Asyn
: This test case uses STRIDE test points to verify the receipt of an asynchronous event.
: uses STRIDE test points to verify the receipt of an asynchronous event.




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

Revision as of 20:22, 3 June 2009

Tests Description

s2_testintro_cclass

This example covers the following topics:

This demonstrates the declaration and use of a "C Class" test unit -- a structure with function pointer members and optional member data. The test unit contains the following test cases:

testBasics_PASS
calls a simple FUT (function under test) and uses srEXPECT macros to validate the return value. All assertions pass for this test case.
testBasics_FAIL
calls the same FUT and uses srEXPECT macros to validate the return value. All assertions fail for this test case.

This example also demonstrates the use of 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.

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

s2_testintro_flist

This example covers the following topics:

This example demonstrates the declaration and use of a function list test unit (flist) which is made up of individual C linkage test functions. Flists are the simplest kind of test unit that can be created for c-only compilation units, but they lack some of the capabilities of CClass test units (such as member data and the ability to use non-extern functions as tests).

This test unit contains three test cases: the first two are identical to the CClass example above. The third test - testBasics_Asyn_PASS - demonstrates a technique for simple asynchronous event testing by creating a timer using the PAL API and validating that the registered callback was invoked.

s2_testintro_testdoubles

This example covers the following topics:

 * fake functions

This example demonstrates the use of STRIDE's test double technique to implement mocks and fakes. The function being doubled for these examples is s2CopyString (in s2_testintro_source.c). The example includes the following test cases:

testDoubles_Normal
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
does 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 previous test, does a dynamic replacement of s2CopyString's call to s2MoveString, this time to a fake implementation named s2MoveString_Fake. In this case, s2MoveString_Fake forces an error condition. The testDoubles_Fake test verifies that the error is handled as expected by s2CopySting.

s2_testintro_testpoints

This example covers the following topics:

  • event verification
 * state verification
  • asynchronous code validation

The example includes the following test cases:

testPoints_Event
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
uses STRIDE test points to verify the operation of a state machine.
testPoints_Asyn
uses STRIDE test points to verify the receipt of an asynchronous event.